This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(worker): "delayed_job" support added
Resolves #42
- Loading branch information
Showing
7 changed files
with
278 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
module Drivers | ||
module Worker | ||
class DelayedJob < Drivers::Worker::Base | ||
adapter :delayed_job | ||
allowed_engines :delayed_job | ||
output filter: [:process_count, :syslog, :queues] | ||
|
||
def raw_out | ||
output = node['defaults']['worker'].merge( | ||
node['deploy'][app['shortname']]['worker'] || {} | ||
).symbolize_keys | ||
output[:queues] = node['deploy'][app['shortname']]['worker']['queues'] || '' | ||
output | ||
end | ||
|
||
def configure(context) | ||
add_delayed_job_monit(context) | ||
end | ||
|
||
def after_deploy(context) | ||
(1..process_count).each do |process_number| | ||
context.execute "monit restart delayed_job_#{app['shortname']}-#{process_number}" do | ||
retries 3 | ||
end | ||
end | ||
end | ||
alias after_undeploy after_deploy | ||
|
||
private | ||
|
||
def add_delayed_job_monit(context) | ||
app_shortname = app['shortname'] | ||
deploy_to = deploy_dir(app) | ||
output = out | ||
env = environment | ||
|
||
context.template File.join(node['monit']['basedir'], "delayed_job_#{app_shortname}.monitrc") do | ||
mode '0640' | ||
source 'delayed_job.monitrc.erb' | ||
variables application: app_shortname, out: output, deploy_to: deploy_to, environment: env | ||
end | ||
|
||
context.execute 'monit reload' | ||
end | ||
|
||
def process_count | ||
[out[:process_count].to_i, 1].max | ||
end | ||
|
||
def environment | ||
framework = Drivers::Framework::Factory.build(app, node) | ||
app['environment'].merge(framework.out[:deploy_environment] || {}) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
|
||
describe Drivers::Worker::DelayedJob do | ||
it 'receives and exposes app and node' do | ||
driver = described_class.new(aws_opsworks_app, node) | ||
|
||
expect(driver.app).to eq aws_opsworks_app | ||
expect(driver.node).to eq node | ||
expect(driver.options).to eq({}) | ||
end | ||
|
||
it 'returns proper out data' do | ||
expect(described_class.new(aws_opsworks_app, node).out).to eq( | ||
process_count: 2, | ||
syslog: true, | ||
queues: 'test_queue' | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<% ([@out[:process_count].to_i || 1].max).times do |n| %> | ||
<% identifier = "#{@application}-#{n+1}" %> | ||
<% pid_dir = "#{@deploy_to}/shared/pids/" %> | ||
<% syslog = !!@out[:syslog] ? "2>&1 | logger -t delayed_job-#{identifier}" : '' %> | ||
<% queues = @out[:queues].present? ? '--queues=' + Array.wrap(@out[:queues]).join(',') : '' %> | ||
|
||
check process delayed_job_<%= identifier.to_s %> | ||
with pidfile <%= pid_dir.to_s %>delayed_job.<%= n %>.pid | ||
start program = "/bin/su - <%= node['deployer']['user'] %> -c 'cd <%= File.join(@deploy_to, 'current') %> && <%= @environment.map {|k,v| "#{k}=\"#{v}\""}.join(' ') %> bin/delayed_job start --pid-dir=<%= pid_dir.to_s %> -i <%= n %> <%= queues.to_s %> <%= syslog.to_s %>'" with timeout 90 seconds | ||
stop program = "/bin/su - <%= node['deployer']['user'] %> -c 'cd <%= File.join(@deploy_to, 'current') %> && <%= @environment.map {|k,v| "#{k}=\"#{v}\""}.join(' ') %> bin/delayed_job stop --pid-dir=<%= pid_dir.to_s %> -i <%= n %>'" with timeout 90 seconds | ||
group delayed_job_<%= @application.to_s %>_group | ||
|
||
<% end %> |