Skip to content

Commit

Permalink
Hobson::Worker < Resque::Worker so i could set -bash to hobson rather…
Browse files Browse the repository at this point in the history
… then resque
  • Loading branch information
Jared Grippe authored and jaredatron committed Feb 25, 2012
1 parent 08bb9be commit b3c9f92
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/hobson.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'hobson/version'

require 'redis'
require 'redis/slave'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -101,5 +106,6 @@ def files

end

require 'hobson/version'
require 'hobson/logger'
require 'hobson/redis'
25 changes: 25 additions & 0 deletions lib/hobson/worker.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b3c9f92

Please sign in to comment.