Class: RQ::ReSubmitter

Inherits:
MainHelper show all
Defined in:
lib/rq/resubmitter.rb

Overview

the Submitter class is responsible for submitting commands to the queue, the commands it submits are taken from the command line, stdin, or the specified infile. the format of commands read from stdin or file is either a simple list of commands, one per line, where blank lines and comments (#) are ignored OR it is valid yaml input. if the Submitter sees the token ‘—’ in the input stream it is assumed the input is yaml. for an example of valid yaml input examine the output of a Lister using

rq q list

the output of other commands, such as that of a Querier may also be used as input to submit

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

Methods inherited from MainHelper

#dumping_yaml_tuples, #field_match, #init_job_stdin!, #initialize, #loadio, #loadyaml, #set_q

Methods included from Logging

append_features

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

#resubmitObject

–{{{



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
89
90
91
92
93
94
# File 'lib/rq/resubmitter.rb', line 26

def resubmit
#--{{{
  set_q

  @priority = @options['priority']
  debug{ "priority <#{ @priority }>" }

  @tag = @options['tag']
  debug{ "tag <#{ @tag }>" }

  @runner = @options['runner']
  debug{ "runner <#{ @runner }>" }

  @restartable = @options['restartable']
  debug{ "restartable <#{ @restartable }>" }

  @infile = @options['infile'] 
  debug{ "infile <#{ @infile }>" }

  @data = @options['data'] 
  debug{ "data <#{ @data }>" }

  if job_stdin == '-' and stdin?
    abort "cannot specify both jobs and job input on stdin"
  end


  jobs = [] 

  if @infile
    open(@infile) do |f|
      debug{ "reading jobs from <#{ @infile }>" }
      loadio f, @infile, jobs 
    end
  end

  if stdin? 
    debug{ "reading jobs from <stdin>" }
    loadio stdin, 'stdin', jobs 
  end
  jobs.each{|job| @argv << Integer(job['jid'])}

  abort "no jobs specified!" if @argv.empty?

  init_job_stdin!
  
  puts '---'
  @q.transaction do
    jobs = @q.list(*@argv)
    jobs.each do |job|
      job['priority'] = @priority if @options.has_key?('priority')
      job['tag'] = @tag if @options.has_key?('tag')
      job['runner'] = @runner if @options.has_key?('runner')
      job['restartable'] = @restartable if @options.has_key?('restartable')
      job['stdin'] = @job_stdin
      job['data'] = @data
      unless job['state'] =~ %r/running/io
        resubmitted = nil
        @q.resubmit(job){|resubmitted|}
        puts '-'
        resubmitted.fields.each{|f| puts " #{ f }: #{ resubmitted[f] }" }
      end
    end
  end

  jobs = nil
  self
#--}}}
end