Sha256: c82da1092bf41abb017d88aab7d40fd14d93ac520866bff062beff01ecc84f26
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
unless defined? $__rq_jobrunner__ module RQ #{{{ LIBDIR = File::dirname(File::expand_path(__FILE__)) + File::SEPARATOR unless defined? LIBDIR require 'drb/drb' require LIBDIR + 'util' class JobRunner #{{{ include DRbUndumped attr :job attr :jid attr :cid attr :shell attr :command alias pid cid def initialize job #{{{ @job = job @jid = job['jid'] @command = job['command'] @shell = job['shell'] || 'bash' @r,@w = IO::pipe @env = {} @job.fields.each do |field| key = "RQ_#{ field }".upcase.gsub(%r/\s+/,'_') val = @job[field] @env[key] = "#{ val }" end @cid = Util::fork do begin @env.each{|k,v| ENV[k] = v} ENV['RQ_PID'] = "#{ $$ }" @w.close STDIN.reopen @r if File::basename(@shell) == 'bash' || File::basename(@shell) == 'sh' exec [@shell, "__rq_job__#{ @jid }__#{ File::basename(@shell) }__"], '--login' else exec [@shell, "__rq_job__#{ @jid }__#{ File::basename(@shell) }__"], '-l' end rescue Exception => e STDERR.puts(Util::errmsg(e)) end end @r.close #}}} end def run #{{{ @w.puts @command @w.close #}}} end #}}} end # class JobRunner #}}} end # module RQ $__rq_jobrunner__ = __FILE__ end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rq-0.1.7 | lib/rq-0.1.7/jobrunner.rb |