Add delayed_job version 2.1.4 back into our environment: db migration,
initializer, and script.
Created systemd configuration file. Spec file installs config file into
/lib/systemd/system.
The service is named conductor-delayed_job and can be controlled through
either of these two commands:
"systemctl start/stop/status conductor-delayed_job.service"
"service conductor-delayed_job start/stop/status"
Service brings up 2 workers to process the queue.
---
aeolus-conductor.spec.in | 28 +++++++++++++++
conf/conductor-delayed_job.systemd | 16 ++++++++
src/Gemfile | 1 +
src/config/initializers/delayed_job.rb | 9 +++++
.../migrate/20110124103216_create_delayed_jobs.rb | 37 --------------------
.../migrate/20120423224618_create_delayed_jobs.rb | 21 +++++++++++
src/script/delayed_job | 5 +++
7 files changed, 80 insertions(+), 37 deletions(-)
create mode 100644 conf/conductor-delayed_job.systemd
create mode 100644 src/config/initializers/delayed_job.rb
delete mode 100644 src/db/migrate/20110124103216_create_delayed_jobs.rb
create mode 100644 src/db/migrate/20120423224618_create_delayed_jobs.rb
create mode 100755 src/script/delayed_job
diff --git a/aeolus-conductor.spec.in b/aeolus-conductor.spec.in
index 3008b0c..dcd60f1 100644
--- a/aeolus-conductor.spec.in
+++ b/aeolus-conductor.spec.in
@@ -38,6 +38,7 @@ Requires: rubygem(pg)
Requires: rubygem(ruby-net-ldap)
Requires: rubygem(oauth)
Requires: rubygem(rake)
+Requires: rubygem(delayed_job) >= 2.1.4
Requires: postgresql
Requires: postgresql-server
Requires: system-logos
@@ -63,6 +64,10 @@ Requires: rubygem(thin) >= 1.2.5
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
+Requires(post): systemd-units
+Requires(preun): systemd-units
+Requires(postun): systemd-units
+
%description daemons
The configuration and daemons necessary to run and proxy the Aeolus Conductor.
@@ -137,6 +142,7 @@ getent passwd aeolus >/dev/null || \
%{__mkdir} -p %{buildroot}%{app_root}
%{__mkdir} -p %{buildroot}%{doc_root}
%{__mkdir} -p %{buildroot}%{_initrddir}
+%{__mkdir} -p %{buildroot}%{_unitdir}/systemd/system
%{__mkdir} -p %{buildroot}%{_sysconfdir}/sysconfig
%{__mkdir} -p %{buildroot}%{_sysconfdir}/httpd/conf.d
%{__mkdir} -p %{buildroot}%{_sysconfdir}/logrotate.d
@@ -247,6 +253,7 @@ done
# copy over init scripts and various config
%{__cp} conf/aeolus-conductor %{buildroot}%{_initrddir}
%{__cp} conf/conductor-dbomatic %{buildroot}%{_initrddir}
+%{__cp} conf/conductor-delayed_job.systemd
%{buildroot}%{_unitdir}/conductor-delayed_job.service
%{__cp} conf/aeolus-conductor-httpd.conf
%{buildroot}%{_sysconfdir}/httpd/conf.d/aeolus-conductor.conf
%{__cp} conf/aeolus-conductor.logrotate
%{buildroot}%{_sysconfdir}/logrotate.d/aeolus-conductor
%{__cp} conf/aeolus-conductor.sysconf
%{buildroot}%{_sysconfdir}/sysconfig/aeolus-conductor
@@ -265,6 +272,10 @@ touch %{buildroot}%{_localstatedir}/log/%{name}/rails.log
touch %{buildroot}%{_localstatedir}/log/%{name}/dbomatic.log
%{__mkdir} -p %{buildroot}%{app_root}/log
+# delayed_job version 2.1.4 forces the log to be in this location
+# we should be able to change this to /var/log/aeolus-conductor/delayed_job.log
+# with version 3.0
+touch %{buildroot}%{app_root}/log/delayed_job.log
# copy script files over
%{__cp} -r src/script %{buildroot}%{app_root}
@@ -304,18 +315,33 @@ if [ ! -d %{app_root}/app ]; then
fi
%post daemons
+if [ $1 -eq 1 ] ; then
+ # Initial installation
+ /bin/systemctl daemon-reload >/dev/null 2>&1
+fi
# Register the services
/sbin/chkconfig --add aeolus-conductor
/sbin/chkconfig --add conductor-dbomatic
%preun daemons
if [ $1 = 0 ]; then
+ # Package removal, not upgrade
+ /bin/systemctl --no-reload disable conductor-delayed_job.service > /dev/null
2>&1
+ /bin/systemctl stop conductor-delayed_job.service > /dev/null 2>&1
/sbin/service aeolus-conductor stop > /dev/null 2>&1
/sbin/chkconfig --del aeolus-conductor
/sbin/service conductor-dbomatic stop > /dev/null 2>&1
/sbin/chkconfig --del conductor-dbomatic
fi
+%postun daemons
+/bin/systemctl daemon-reload >/dev/null 2>&1 || :
+if [ $1 -ge 1 ] ; then
+ # Package upgrade, not uninstall
+ /bin/systemctl try-restart conductor-delayed_job.service >/dev/null 2>&1
+fi
+
+
%files
%dir %{app_root}
%{app_root}/app
@@ -344,6 +370,7 @@ fi
%files daemons
%{_initrddir}/aeolus-conductor
%{_initrddir}/conductor-dbomatic
+%{_unitdir}/conductor-delayed_job.service
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%config(noreplace) %{_sysconfdir}/sysconfig/aeolus-conductor
%config(noreplace) %{_sysconfdir}/sysconfig/conductor-rails
@@ -351,6 +378,7 @@ fi
%attr(-, aeolus, aeolus) %{_localstatedir}/lib/%{name}
%attr(-, aeolus, aeolus) %{_localstatedir}/run/%{name}
%attr(-, aeolus, aeolus) %{_localstatedir}/log/%{name}
+%attr(-, aeolus, aeolus) %{app_root}/log/delayed_job.log
%doc AUTHORS COPYING
%{_libdir}/../lib/tmpfiles.d/aeolus.conf
diff --git a/conf/conductor-delayed_job.systemd b/conf/conductor-delayed_job.systemd
new file mode 100644
index 0000000..6c1fc55
--- /dev/null
+++ b/conf/conductor-delayed_job.systemd
@@ -0,0 +1,16 @@
+[Unit]
+Description=aeolus delayed_job
+After=syslog.target
+After=postgresql.service
+
+[Service]
+Type=forking
+User=aeolus
+Environment=RAILS_ENV=production
+WorkingDirectory=/usr/share/aeolus-conductor/
+ExecStart=/usr/share/aeolus-conductor/script/delayed_job start -n 2
--pid-dir=/var/run/aeolus-conductor
+ExecStop=/usr/share/aeolus-conductor/script/delayed_job stop
--pid-dir=/var/run/aeolus-conductor
+TimeoutSec=120
+
+[Install]
+WantedBy=multi-user.target
\ No newline at end of file
diff --git a/src/Gemfile b/src/Gemfile
index 529d658..ca7eb59 100644
--- a/src/Gemfile
+++ b/src/Gemfile
@@ -23,6 +23,7 @@ gem 'rails_warden'
gem 'ruby-net-ldap'
gem 'aeolus-image'
gem 'oauth'
+gem 'delayed_job'
group :development, :test do
gem 'rspec-rails'
gem 'rspec-core'
diff --git a/src/config/initializers/delayed_job.rb
b/src/config/initializers/delayed_job.rb
new file mode 100644
index 0000000..6e0d177
--- /dev/null
+++ b/src/config/initializers/delayed_job.rb
@@ -0,0 +1,9 @@
+require 'delayed_job'
+
+Delayed::Worker.backend = :active_record
+Delayed::Worker.destroy_failed_jobs = false
+#Delayed::Worker.sleep_delay = 60
+Delayed::Worker.max_attempts = 2
+#Delayed::Worker.max_run_time = 5.minutes
+#Delayed::Worker.read_ahead = 10
+#Delayed::Worker.delay_jobs = !Rails.env.test?
diff --git a/src/db/migrate/20110124103216_create_delayed_jobs.rb
b/src/db/migrate/20110124103216_create_delayed_jobs.rb
deleted file mode 100644
index d280b57..0000000
--- a/src/db/migrate/20110124103216_create_delayed_jobs.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-#
-# Copyright 2011 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#
http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-class CreateDelayedJobs < ActiveRecord::Migration
- def self.up
- create_table :delayed_jobs, :force => true do |table|
- table.integer :priority, :default => 0 # Allows some jobs to jump to the
front of the queue
- table.integer :attempts, :default => 0 # Provides for retries, but still
fail eventually.
- table.text :handler # YAML-encoded string of the object
that will do work
- table.text :last_error # reason for last failure (See Note
below)
- table.datetime :run_at # When to run. Could be Time.zone.now
for immediately, or sometime in the future.
- table.datetime :locked_at # Set when a client is working on this
object
- table.datetime :failed_at # Set when all retries have failed
(actually, by default, the record is deleted instead)
- table.string :locked_by # Who is working on this object (if
locked)
- table.timestamps
- end
-
- add_index :delayed_jobs, [:priority, :run_at], :name =>
'delayed_jobs_priority'
- end
-
- def self.down
- drop_table :delayed_jobs
- end
-end
diff --git a/src/db/migrate/20120423224618_create_delayed_jobs.rb
b/src/db/migrate/20120423224618_create_delayed_jobs.rb
new file mode 100644
index 0000000..943ff9b
--- /dev/null
+++ b/src/db/migrate/20120423224618_create_delayed_jobs.rb
@@ -0,0 +1,21 @@
+class CreateDelayedJobs < ActiveRecord::Migration
+ def self.up
+ create_table :delayed_jobs, :force => true do |table|
+ table.integer :priority, :default => 0 # Allows some jobs to jump to the
front of the queue
+ table.integer :attempts, :default => 0 # Provides for retries, but still
fail eventually.
+ table.text :handler # YAML-encoded string of the object
that will do work
+ table.text :last_error # reason for last failure (See Note
below)
+ table.datetime :run_at # When to run. Could be Time.zone.now
for immediately, or sometime in the future.
+ table.datetime :locked_at # Set when a client is working on this
object
+ table.datetime :failed_at # Set when all retries have failed
(actually, by default, the record is deleted instead)
+ table.string :locked_by # Who is working on this object (if
locked)
+ table.timestamps
+ end
+
+ add_index :delayed_jobs, [:priority, :run_at], :name =>
'delayed_jobs_priority'
+ end
+
+ def self.down
+ drop_table :delayed_jobs
+ end
+end
diff --git a/src/script/delayed_job b/src/script/delayed_job
new file mode 100755
index 0000000..edf1959
--- /dev/null
+++ b/src/script/delayed_job
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.join(File.dirname(__FILE__), '..',
'config', 'environment'))
+require 'delayed/command'
+Delayed::Command.new(ARGV).daemonize
--
1.7.7.6