Skip to content

Commit f7255e5

Browse files
nuxllifearenales
authored andcommitted
Adding env vars to configure worker
In order to make it easy to configure the worker component (set how many times it should be respawned; if it should be spawned by this process or it will be invoked elsewhere), couple optional env vars were added.
1 parent be44d2d commit f7255e5

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Rakefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ desc "Work the delayed_job queue."
4646
task :work_jobs do
4747
Delayed::Job.delete_all
4848

49-
3.times do
49+
worker_retry = Integer(ENV["WORKER_RETRY"] || 3)
50+
worker_retry.times do
5051
Delayed::Worker.new(
5152
min_priority: ENV["MIN_PRIORITY"],
5253
max_priority: ENV["MAX_PRIORITY"]

app.json

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
"ENFORCE_SSL": {
2424
"description": "Force all clients to connect over SSL",
2525
"value": "true"
26+
},
27+
"WORKER_EMBEDDED": {
28+
"description": "Force worker threads to be spawned by main process",
29+
"value": "true"
30+
},
31+
"WORKER_RETRY": {
32+
"description": "Number of times to respawn the worker thread if it fails",
33+
"value": "3"
2634
}
2735
},
2836
"addons": [

config/unicorn.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# as there's no need for the master process to hold a connection
1010
ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base)
1111

12-
@delayed_job_pid ||= spawn("bundle exec rake work_jobs")
12+
@delayed_job_pid ||= spawn("bundle exec rake work_jobs") unless ENV["WORKER_EMBEDDED"] == "false"
1313

1414
sleep 1
1515
end

0 commit comments

Comments
 (0)