/
delayed_job.rb
94 lines (69 loc) · 2.02 KB
/
delayed_job.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
gem 'delayed_job_active_record'
gem 'delayed_job_admin'
if config["admin"]
inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do
<<-RUBY
def delayed_job_admin_authentication
# authentication_logic_goes_here
true
end
RUBY
end
create_file "readmes/delayed_job_admin.md", <<-MD
# Delayed Job Admin README
Delayed Job Admin console is available at [/delayed_job_admin](http://localhost:3000/delayed_job_admin).
```
open http://localhost:3000/delayed_job_admin
```
## Steps to complete
### Authentication
By default, there is no authentication or authorization protecting access to `/delayed_job_admin`.
Please go to `app/controllers/application_controller.rb` and edit the following method:
```ruby
def delayed_job_admin_authentication
# authentication_logic_goes_here
true
end
```
For example, if you are using the Devise gem and have an Admin model:
```ruby
def delayed_job_admin_authentication
authenticate_admin!
end
```
MD
end
if scroll? "eycloud_recipes_on_deploy"
gem 'eycloud-recipe-delayed_job', :group => :eycloud
end
after_bundler do
generate 'delayed_job'
if scroll? "eycloud_recipes_on_deploy"
say_wizard 'Installing deploy hooks to restart delayed_job after deploys'
run "touch deploy/before_restart.rb"
append_file "deploy/before_restart.rb", <<-RUBY
on_app_servers_and_utilities do
node[:applications].each do |app_name, data|
sudo 'echo "sleep 20 && monit -g dj_\#{app_name} restart all" | at now'
end
end
RUBY
append_file "deploy/cookbooks/main/recipes/default.rb", "\nrequire_recipe 'delayed_job'\n"
end
end
after_everything do
say_custom "readme", "Delayed Job Admin"
run %q{cat "readmes/delayed_job_admin.md"}
end
__END__
name: Delayed Job
description: Use Delayed Job to handle background jobs
author: drnic
exclusive: worker
category: worker
tags: [worker,background-tasks]
run_after: [eycloud_recipes_on_deploy]
config:
- admin:
type: boolean
prompt: "Install simple admin interface to Delayed Job?"