RQ::MainHelper (Class)

In: lib/rq-3.0.0/mainhelper.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 MainHelper class abstracts some of the common functions the various Main delegates require

Methods

External Aliases

'stdin' -> 'stdin?'
'job_stdin' -> 'job_stdin?'
'quiet' -> 'quiet?'

Attributes

argv  [R] 
cmd  [R] 
dot_rq_dir  [R] 
env  [R] 
fields  [R] 
job_stdin  [R] 
main  [R] 
mode  [R] 
options  [R] 
q  [R] 
qpath  [R] 
quiet  [R] 
stdin  [R] 

Included Modules

Util Logging

Public Class methods

[Source]

    # File lib/rq-3.0.0/mainhelper.rb, line 37
37:       def initialize main
38: #--{{{
39:         @main = main
40:         @logger = main.logger
41:         @argv = main.argv
42:         @env = main.env
43:         @stdin = main.stdin
44:         @job_stdin = main.job_stdin
45:         @cmd = main.cmd
46:         @options = main.options
47:         @qpath = main.qpath
48:         @mode = main.mode
49:         @quiet = main.quiet
50:         @fields = main.fields
51:         @dot_rq_dir = main.dot_rq_dir
52:         @q = nil 
53: #--}}}
54:       end

Public Instance methods

[Source]

     # File lib/rq-3.0.0/mainhelper.rb, line 132
132:       def dumping_yaml_tuples
133: #--{{{
134:         fields = nil
135:         dump = lambda do |tuple|
136:           puts '---'
137:           if fields.nil?
138:             if @fields
139:               fields = field_match @fields, tuple.fields
140:             else
141:               fields = tuple.fields
142:             end
143:           end
144:           dump = lambda do |tuple|
145:             puts '-'
146:             fields.each{|f| puts " #{ f }: #{ tuple[ f ] }"}
147:           end
148:           dump[tuple]
149:         end
150:         lambda{|tuple| dump[tuple]}
151: #--}}}
152:       end

[Source]

     # File lib/rq-3.0.0/mainhelper.rb, line 153
153:       def field_match srclist, dstlist
154: #--{{{
155:         fields = dstlist.select do |dst|
156:           srclist.map do |src|
157:             re =
158:               if src =~ %/^[a-zA-Z0-9_-]+$/
159:                 %/^#{ src }/i
160:               else
161:                 %/#{ src }/i
162:               end
163:             src == dst or dst =~ re
164:           end.any?
165:         end.uniq
166: #--}}}
167:       end

[Source]

     # File lib/rq-3.0.0/mainhelper.rb, line 168
168:       def init_job_stdin!
169: #--{{{
170:         if @job_stdin == '-'
171:           tmp = Tempfile::new "#{ Process::pid  }_#{ rand 42 }"
172:           while((buf = STDIN.read(8192))); tmp.write buf; end
173:           tmp.close
174:           @job_stdin = tmp.path 
175:         end
176:         @job_stdin
177: #--}}}
178:       end

[Source]

     # File lib/rq-3.0.0/mainhelper.rb, line 92
 92:       def loadio io, path, jobs
 93: #--{{{
 94:         while((line = io.gets))
 95:           if line =~ %/^---\s*$/o
 96:             loadyaml io, path, jobs
 97:           else
 98:             # line.gsub!(%r/(?:^\s+)|(?:\s+$)|(?:#.*$)/o, '')
 99:             line.strip!
100:             next if line.empty?
101:             job = Job::new
102:             if((m =  %/^\s*(?:jid\s*=\s*)?(\d+)\s*$/io.match(line)))
103:               job['jid'] = Integer(m[1])
104:             else
105:               job['command'] = line
106:             end
107:             jobs << job
108:           end
109:         end
110: #--}}}
111:       end

[Source]

    # File lib/rq-3.0.0/mainhelper.rb, line 67
67:       def loadio io, path, jobs
68: #--{{{
69:         while((line = io.gets))
70:           if line =~ %/^---\s*$/o
71:             loaded = YAML::load io 
72:             raise "no jobs in <#{ path }>" unless 
73:               Array === loaded and 
74:               Hash === loaded.first and Hash === loaded.last
75:             loaded.each{|job| jobs << job}
76:             loaded = nil
77:           else
78:             # line.gsub!(%r/(?:^\s+)|(?:\s+$)|(?:#.*$)/o, '')
79:             line.strip!
80:             next if line.empty?
81:             job = Job::new
82:             if((m =  %/^\s*(?:jid\s*=\s*)?(\d+)\s*$/io.match(line)))
83:               job['jid'] = Integer(m[1])
84:             else
85:               job['command'] = line
86:             end
87:             jobs << job
88:           end
89:         end
90: #--}}}
91:       end

[Source]

     # File lib/rq-3.0.0/mainhelper.rb, line 112
112:       def loadyaml io, path, jobs
113: #--{{{
114:         h = nil
115:         while((line = io.gets))
116:           line.strip!
117:           next if line.empty?
118:           case line
119:             when %/^\s*-\s*$/
120:               jobs << h if h
121:               h = {}
122:             else
123:               k, v = line.split %/:/, 2
124:               k.strip!
125:               v.strip!
126:               h[k] = v
127:           end
128:         end
129:         jobs << h if h
130: #--}}}
131:       end

[Source]

    # File lib/rq-3.0.0/mainhelper.rb, line 55
55:       def set_q
56: #--{{{
57:         raise "q <#{ @qpath }> does not exist" unless test ?d, @qpath
58:         @q = JobQueue::new @qpath, 'logger' => @logger
59:         if @options['snapshot']
60:           ss = "#{ $0 }_#{ Process::pid }_#{ Thread::current.object_id.abs }_#{ rand Time::now.to_i  }".gsub(%|/|o,'_')
61:           qtmp = File::join Dir::tmpdir, ss
62:           @q = @q.snapshot qtmp, @options['retries']
63:           at_exit{ FileUtils::rm_rf qtmp }
64:         end
65: #--}}}
66:       end

[Validate]