Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Hobson::Worker < Resque::Worker so i could set -bash to hobson rather…

… then resque
  • Loading branch information...
commit b3c9f9222bf5fc562a02a62336ac36e1d63f60fc 1 parent 08bb9be
Jared Grippe authored committed
Showing with 35 additions and 4 deletions.
  1. +10 −4 lib/hobson.rb
  2. +25 −0 lib/hobson/worker.rb
View
14 lib/hobson.rb
@@ -1,3 +1,5 @@
+require 'hobson/version'
+
require 'redis'
require 'redis/slave'
@@ -27,27 +29,30 @@ module Hobson
autoload :Artifacts, 'hobson/artifacts'
autoload :Project, 'hobson/project'
autoload :Server, 'hobson/server'
+ autoload :Worker, 'hobson/worker'
autoload :CI, 'hobson/ci'
# become a resque-worker and handle hobson resque jobs
def work! options={}
options[:pidfile] ||= ENV['PIDFILE']
+ self.resque # ensure resque is all setup
+
work = proc{
- worker = resque::Worker.new('*')
+ worker = Worker.new
worker.verbose = true
worker.very_verbose = $DEBUG
- logger.info "started resque worker #{worker}"
+ logger.info "started worker #{worker}"
File.open(options[:pidfile], 'w') { |f| f << worker.pid } if options[:pidfile]
worker.work
}
if options[:daemonize]
pid = fork{ work.call }
- puts "Daemonized a resque worker with pid #{pid}"
+ puts "Daemonized a worker with pid #{pid}"
Process.detach(pid)
else
- puts "Becoming a resque worker"
+ puts "Becoming a worker"
work.call
end
end
@@ -101,5 +106,6 @@ def files
end
+require 'hobson/version'
require 'hobson/logger'
require 'hobson/redis'
View
25 lib/hobson/worker.rb
@@ -0,0 +1,25 @@
+class Hobson::Worker < Resque::Worker
+
+ def initialize
+ @parent_pid = $$
+ super '*'
+ end
+
+ def parent?
+ $$ == @parent_pid
+ end
+
+ def child?
+ !parent?
+ end
+
+ def proc_name
+ parent? ? "hobson-#{Hobson.git_version}" : "hobson-worker:parent-#{@parent_pid}"
+ end
+
+ def procline(string)
+ $0 = "#{proc_name}: #{string}"
+ log! $0
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.