Class: RQ::Submitter

Inherits:
MainHelper show all
Defined in:
lib/rq/submitter.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 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

#submitObject

–{{{



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
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rq/submitter.rb', line 26

def submit
#--{{{
  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 }>" }

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

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

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

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

  jobs = [] 

  unless @argv.empty?
    job = Job::new
    job['command'] = @argv.join(' ') 
    job['priority'] = @priority
    job['tag'] = @tag 
    job['runner'] = @runner
    job['restartable'] = @restartable
    jobs << job
  end

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

  if jobs.empty? and stdin? 
    debug{ "reading jobs from <stdin>" }
    loadio stdin, 'stdin', jobs 
  end

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

  init_job_stdin!
  
  state = @stage ? 'holding' : 'pending'

  jobs.each do |job|
    job['state'] = state
    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 if @job_stdin
    job['data'] = @data if @data
  end

  if @options['quiet'] 
    @q.submit(*jobs)
  else
    @q.submit(*jobs, &dumping_yaml_tuples)
  end
    
  jobs = nil
  self
#--}}}
end