From 169cef6bf923af930c4c31a57012791f5071e7bb Mon Sep 17 00:00:00 2001 From: Leandro Segovia Date: Fri, 19 Feb 2016 13:34:19 -0300 Subject: [PATCH] feat(): add delayed job recipe closes #32 --- README.md | 1 + .../templates/application/assets/README.md.erb | 5 ++++- .../application/recipes/asks/delayed_job.rb | 2 ++ .../templates/application/recipes/delayed_job.rb | 16 ++++++++++++++++ lib/potassium/templates/application/template.rb | 2 ++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 lib/potassium/templates/application/recipes/asks/delayed_job.rb create mode 100644 lib/potassium/templates/application/recipes/delayed_job.rb diff --git a/README.md b/README.md index bfdb9378..19b019cc 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ The following optional integrations are added too: - [ActiveAdmin](http://activeadmin.info) for admin interfaces. - [ActiveAdminAddons](https://github.com/platanus/activeadmin_addons) for some help with ActiveAdmin. - [Pundit](https://github.com/elabs/pundit) for role-based authorization. +- [DelayedJob](https://github.com/collectiveidea/delayed_job) to execute longer tasks in the background. A few more things are added to the project: diff --git a/lib/potassium/templates/application/assets/README.md.erb b/lib/potassium/templates/application/assets/README.md.erb index 21a95a9d..22d25934 100644 --- a/lib/potassium/templates/application/assets/README.md.erb +++ b/lib/potassium/templates/application/assets/README.md.erb @@ -61,4 +61,7 @@ For managing uploads, this project uses [Paperclip](https://github.com/thoughtbo <% end-%> ### Admin As a way to speed up development of an admin interface, we're using [ActiveAdmin](https://github.com/activeadmin/activeadmin) - +<% if selected?(:delayed_job) %> +### Queue System +For managing tasks in the background, this project uses [DelayedJob](https://github.com/collectiveidea/delayed_job) +<% end-%> diff --git a/lib/potassium/templates/application/recipes/asks/delayed_job.rb b/lib/potassium/templates/application/recipes/asks/delayed_job.rb new file mode 100644 index 00000000..c3a4aded --- /dev/null +++ b/lib/potassium/templates/application/recipes/asks/delayed_job.rb @@ -0,0 +1,2 @@ +use_delayed_job = Ask.confirm "Do you want to use delayed jobs?" +set(:delayed_job, use_delayed_job) diff --git a/lib/potassium/templates/application/recipes/delayed_job.rb b/lib/potassium/templates/application/recipes/delayed_job.rb new file mode 100644 index 00000000..0b35763d --- /dev/null +++ b/lib/potassium/templates/application/recipes/delayed_job.rb @@ -0,0 +1,16 @@ +if selected?(:delayed_job) + gather_gem "delayed_job_active_record" + + delayed_job_config = "config.active_job.queue_adapter = :delayed_job" + application(delayed_job_config) + + after(:gem_install) do + generate "delayed_job:active_record" + + if selected?(:heroku) + gsub_file "Procfile", /^.*$/m do |match| + "#{match}worker: bundle exec rake jobs:work" + end + end + end +end diff --git a/lib/potassium/templates/application/template.rb b/lib/potassium/templates/application/template.rb index d8955726..e90fe33c 100644 --- a/lib/potassium/templates/application/template.rb +++ b/lib/potassium/templates/application/template.rb @@ -11,6 +11,7 @@ eval_file "recipes/asks/database.rb" eval_file "recipes/asks/devise.rb" eval_file "recipes/asks/admin.rb" + eval_file "recipes/asks/delayed_job.rb" eval_file "recipes/asks/pundit.rb" eval_file "recipes/asks/i18n.rb" eval_file "recipes/asks/api.rb" @@ -33,6 +34,7 @@ eval_file "recipes/devise.rb" eval_file "recipes/admin.rb" eval_file "recipes/angular_admin.rb" + eval_file "recipes/delayed_job.rb" eval_file "recipes/pundit.rb" eval_file "recipes/testing.rb" eval_file "recipes/production.rb"