Class: RQ::Updater
- Inherits:
-
MainHelper
- Object
- MainHelper
- RQ::Updater
- Defined in:
- lib/rq/updater.rb
Overview
the Updater class reads jids from the command line and then looks for key=value pairs on the command line, stdin, or from infile. the jids are taken to be jids to update with the key=values pairs scanned
Constant Summary
Constants included from Logging
Logging::DIV0, Logging::DIV1, Logging::DIV2, Logging::DIV3, Logging::EOL, Logging::SEC0, Logging::SEC1, Logging::SEC2, Logging::SEC3
Instance Attribute Summary
Attributes inherited from MainHelper
#argv, #cmd, #dot_rq_dir, #env, #fields, #job_stdin, #loops, #main, #mode, #options, #program, #q, #qpath, #quiet, #stdin
Instance Method Summary collapse
-
#update ⇒ Object
–{{{.
Methods inherited from MainHelper
#dumping_yaml_tuples, #field_match, #init_job_stdin!, #initialize, #loadio, #loadyaml, #set_q
Methods included from Logging
Methods included from Logging::LogMethods
#debug, #error, #fatal, #info, #logerr, #logger, #logger=, #warn
Methods included from Util
#alive?, append_features, #btrace, #columnize, #defval, #emsg, #erreq, #errmsg, #escape, #escape!, #exec, export, #fork, #getopt, #hashify, #hms, #host, #hostname, #klass, #maim, #mcp, #realpath, #stamptime, #system, #timestamp, #tmpnam, #uncache, #which_ruby
Constructor Details
This class inherits a constructor from RQ::MainHelper
Instance Method Details
#update ⇒ Object
–{{{
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rq/updater.rb', line 16 def update #--{{{ set_q jids = [] kvs = {} kvs.update "stdin" => job_stdin if job_stdin? # # scan argv for jids to update # list, @argv = @argv.partition{|arg| arg =~ %r/^\s*(?:jid\s*=\s*)?\d+\s*$/} list.each{|elem| jids << Integer(elem[%r/\d+/])} list, @argv = @argv.partition{|arg| arg =~ %r/^\s*(?:p(?:ending)|h(?:olding))\s*$/} list.each{|elem| jids << elem.strip.downcase} # # scan argv for key=val pairs # keyeqpat = %r/\s*([^\s=]+)\s*=\s*([^\s]*)\s*$/ list, @argv = @argv.partition{|arg| arg =~ keyeqpat} list.each do |elem| m = elem.match(keyeqpat) k, v = m[1], m[2] k = (k.empty? ? nil : k.strip) v = (v.empty? ? nil : v.strip) v = case v when %r/^\s*(?:nil|null?)\s*$/io nil else v end kvs[k] = v end unless @argv.empty? raise "don't know what to do with crap arguments <#{ @argv.join ' ' }>" end # # scan stdin for jids to update iff in pipeline # if stdin? #pat = %r/^(?:\s*jid\s*:)?\s*(\d+)\s*$/io while((line = stdin.gets)) case line when %r/^(?:\s*jid\s*:)?\s*(\d+)\s*$/io jids << Integer($1) when %r/^\s*p(?:ending)\s*$/io jids << 'pending' when %r/^\s*h(?:olding)\s*$/io jids << 'holding' else next end end end #jids.map!{|jid| jid =~ %r/^\s*\d+\s*$/o ? Integer(jid) : jid} #raise "no jids" if jids.empty? # # if no jids were specified simply update ALL pending and holding jobs # jids << 'pending' << 'holding' if jids.empty? # # apply the update # if @options['quiet'] @q.update(kvs,*jids) else @q.update(kvs,*jids, &dumping_yaml_tuples) end #--}}} end |