RQ::Refresher (Class)

In: lib/rq-3.0.0/refresher.rb
Parent: Object
MainHelper StatusLister Snapshotter ReSubmitter Feeder Deleter Toucher Relayer Executor Submitter Locker IOViewer Backer Cron Configurator Lister Rotater Creator Recoverer Updater Querier ::Hash ConfigFile DRbUndumped JobRunner Main QDB JobQueue JobRunnerDaemon Array SleepCycle Job ArrayFields ::OrderedHash OrderedAutoHash LogMethods Refresher ResourceManager Resource lib/rq-3.0.0/refresher.rb lib/rq-3.0.0/snapshotter.rb lib/rq-3.0.0/deleter.rb lib/rq-3.0.0/feeder.rb lib/rq-3.0.0/configurator.rb lib/rq-3.0.0/cron.rb lib/rq-3.0.0/jobqueue.rb lib/rq-3.0.0/rotater.rb lib/rq-3.0.0/backer.rb lib/rq-3.0.0/toucher.rb lib/rq-3.0.0/qdb.rb lib/rq-3.0.0/configfile.rb lib/rq-3.0.0/mainhelper.rb lib/rq-3.0.0/lister.rb bin/rq.rb lib/rq-3.0.0/statuslister.rb lib/rq-3.0.0/updater.rb lib/rq-3.0.0/jobrunner.rb lib/rq-3.0.0/job.rb lib/rq-3.0.0/creator.rb lib/rq-3.0.0/sleepcycle.rb lib/rq-3.0.0/executor.rb lib/rq-3.0.0/resubmitter.rb lib/rq-3.0.0/orderedautohash.rb lib/rq-3.0.0/resourcemanager.rb lib/rq-3.0.0/resource.rb lib/rq-3.0.0/jobrunnerdaemon.rb lib/rq-3.0.0/recoverer.rb lib/rq-3.0.0/querier.rb lib/rq-3.0.0/ioviewer.rb lib/rq-3.0.0/locker.rb lib/rq-3.0.0/submitter.rb lib/rq-3.0.0/relayer.rb Usage Util LogClassMethods LoggerExt LogMethods Logging RQ Module: RQ

the job of the Refresher is to maintain a lease on a file that has been locked. the method is simply to touch the file at a certain interval thereby keeping it ‘fresh’. a separate process, vs. a thread, is used for this task to eliminate any chance that the ruby interpreter might put all threads to sleep for some blocking tasks, like fcntl based locks which are used heavily in RQ, resulting in a a prematurely stale lockfile

Methods

kill   new  

Constants

SIGNALS = %w(SIGTERM SIGINT SIGKILL)

Attributes

path  [R] 
pid  [R] 
refresh_rate  [R] 

Public Class methods

[Source]

    # File lib/rq-3.0.0/refresher.rb, line 21
21:       def initialize path, refresh_rate = 8
22: #--{{{
23:         @path = path
24:         File::stat path
25:         @refresh_rate = Float refresh_rate
26:         @pipe = IO::pipe
27:         if((@pid = Util::fork))
28:           @pipe.last.close
29:           @pipe = @pipe.first
30:           @thread = Thread::new{loop{@pipe.gets}}
31:           Process::detach @pid
32:         else
33:           begin
34:             pid = Process::pid
35:             ppid = Process::ppid
36:             $0 = "#{ path }.refresher.#{ pid }"
37:             SIGNALS.each{|sig| trap(sig){ raise }}
38:             @pipe.first.close
39:             @pipe = @pipe.last
40:             loop do
41:               FileUtils::touch @path
42:               sleep @refresh_rate
43:               Process::kill 0, ppid
44:               @pipe.puts pid
45:             end
46:           rescue Exception => e
47:             exit!
48:           end
49:         end
50: #--}}}
51:       end

Public Instance methods

[Source]

    # File lib/rq-3.0.0/refresher.rb, line 52
52:       def kill
53: #--{{{
54:         begin
55:           @thread.kill rescue nil
56:           @pipe.close rescue nil
57:           SIGNALS.each{|sig| Process::kill sig, @pid rescue nil}
58:         ensure
59: =begin
60:           n = 42
61:           dead = false
62:           begin
63:             n.times do |i|
64:               Process::kill 0, @pid
65:               sleep 1
66:             end
67:           rescue Errno::ESRCH
68:             dead = true
69:           end
70:           raise "runaway refresher <#{ @pid }> must be killed!" unless dead
71: =end
72: 
73:         end
74: #--}}}
75:       end

[Validate]