Class: PBS::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/pbs/job.rb

Constant Summary collapse

HOSTNAME =
Socket.gethostname

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Job

Needs a connection object and headers Examples of headers found in ‘headers.rb’



14
15
16
17
18
# File 'lib/pbs/job.rb', line 14

def initialize(args = {})
  # Job specific args
  @id = args[:id]
  @conn = args[:conn] || Conn.new
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



10
11
12
# File 'lib/pbs/job.rb', line 10

def conn
  @conn
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/pbs/job.rb', line 9

def id
  @id
end

Instance Method Details

#delete(args = {}) ⇒ Object

Delete job



47
48
49
# File 'lib/pbs/job.rb', line 47

def delete(args = {})
  _pbs_delete()
end

#hold(args = {}) ⇒ Object

Put job on hold



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pbs/job.rb', line 21

def hold(args = {})
  # hold_type::
  # The parameter, hold_type, contains the type of hold to be applied. The possible values are (default is 'u'):
  # "u" : Available to the owner of the job, the batch operator and the batch administrator.
  # "o" : Available to the batch operator and the batch administrator.
  # "s" : Available only to the batch administrator.
  hold_type = args[:hold_type] || "u"

  _pbs_hold(hold_type)
  self
end

#release(args = {}) ⇒ Object

Release job from hold



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pbs/job.rb', line 34

def release(args = {})
  # hold_type::
  # The parameter, hold_type, contains the type of hold to be applied. The possible values are (default is 'u'):
  # "u" : Available to the owner of the job, the batch operator and the batch administrator.
  # "o" : Available to the batch operator and the batch administrator.
  # "s" : Available only to the batch administrator.
  hold_type = args[:hold_type] || "u"

  _pbs_release(hold_type)
  self
end

#status(args = {}) ⇒ Object

Get status of job by creating a Query object



52
53
54
55
# File 'lib/pbs/job.rb', line 52

def status(args = {})
  q = Query.new(type: :job, conn: conn)
  q.find(args.merge(id: id))[0]
end

#submit(args) ⇒ Object

Can submit a script as a file or string

Parameters:

  • args (Hash)

    The options when submitting a job.

Options Hash (args):

  • :string (String)

    The batch script as a string.

  • :file (String)

    The batch script file if a string is not supplied.

  • :qsub (Boolean) — default: true

    Whether the qsub command is used from command line.

  • :headers (Hash) — default: {}

    PBS headers.

  • :resources (Hash) — default: {}

    PBS resources.

  • :envvars (Hash) — default: {}

    PBS environment variables.

Raises:

  • (Error)

    if fail to submit batch job.



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
# File 'lib/pbs/job.rb', line 66

def submit(args)
  string = args.fetch(:string) { File.open(args[:file]).read }
  queue  = args.fetch(:queue, nil)
  qsub   = args.fetch(:qsub, true)

  headers   = args.fetch(:headers,   {})
  resources = args.fetch(:resources, {})
  envvars   = args.fetch(:envvars,   {})

  # Create batch script in tmp file, submit, remove tmp file
  script = Tempfile.new('qsub.')
  begin
    script.write string
    script.close
    if qsub
      _qsub_submit(script.path, queue, headers, resources, envvars)
    else
      _pbs_submit(script.path, queue, headers, resources, envvars)
    end
  ensure
    script.unlink # deletes the temp file
  end

  self
end