Class: Dydra::Job

Inherits:
Resource show all
Defined in:
lib/dydra/job.rb

Overview

Represents a Dydra.com job.

See Also:

Constant Summary

SPEC =

/uuid

%r(^([^/]+)$)
STATUS_UNKNOWN =
:unknown
STATUS_PENDING =
:pending
STATUS_RUNNING =
:running
STATUS_COMPLETED =
:completed
STATUS_FAILED =
:failed
STATUS_ABORTED =
:aborted

Constants inherited from Resource

Resource::HEADERS

Instance Attribute Summary (collapse)

Attributes inherited from Resource

#url

Instance Method Summary (collapse)

Methods inherited from Resource

#<=>, #eql?, #exists?, #get, #head, #inspect, #inspect!, new, #path, #to_rdf, #to_uri

Constructor Details

- (Job) initialize(uuid)

Initializes the job instance.

Parameters:

  • uuid (String, #to_s)

    a valid job UUID



27
28
29
30
# File 'lib/dydra/job.rb', line 27

def initialize(uuid)
  @uuid = uuid.to_s
  super(Dydra::URL.join(@uuid)) # FIXME
end

Instance Attribute Details

- (String) uuid (readonly)

The job UUID.

Returns:

  • (String)


20
21
22
# File 'lib/dydra/job.rb', line 20

def uuid
  @uuid
end

Instance Method Details

- abort! Also known as: abort

This method returns an undefined value.

Aborts this job if it is currently pending or running.



147
148
149
150
# File 'lib/dydra/job.rb', line 147

def abort!
  Dydra::Client.rpc.call('dydra.job.abort', uuid)
  self
end

- (Boolean) aborted?

Returns true if this job was aborted for any reason.

Returns:

  • (Boolean)


77
78
79
# File 'lib/dydra/job.rb', line 77

def aborted?
  status.eql?(:aborted)
end

- (Boolean) completed? Also known as: finished?

Returns true if this job has already completed.

Returns:

  • (Boolean)


60
61
62
# File 'lib/dydra/job.rb', line 60

def completed?
  status.eql?(:completed)
end

- (Time) completed_at

Returns the time when this job finished executing, or nil if it hasn't completed yet.

Returns:

  • (Time)

Raises:

  • (NotImplementedError)


119
120
121
# File 'lib/dydra/job.rb', line 119

def completed_at
  raise NotImplementedError # TODO
end

- (Boolean) done?

Returns true if this job has completed or was aborted, and false if it's currently pending or running.

Returns:

  • (Boolean)


86
87
88
# File 'lib/dydra/job.rb', line 86

def done?
  [:completed, :aborted, :failed].include?(status)
end

- (Boolean) failed?

Returns true if this job failed for some reason.

Returns:

  • (Boolean)


69
70
71
# File 'lib/dydra/job.rb', line 69

def failed?
  status.eql?(:failed)
end

- (Hash) info

Returns detailed information about this job.

Returns:

  • (Hash)


102
103
104
# File 'lib/dydra/job.rb', line 102

def info
  Dydra::Client.rpc.call('dydra.job.info', uuid)
end

- (Boolean) pending?

Returns true if this job is currently pending to run.

Returns:

  • (Boolean)


44
45
46
# File 'lib/dydra/job.rb', line 44

def pending?
  status.eql?(:pending)
end

- (Boolean) running?

Returns true if this job is currently running.

Returns:

  • (Boolean)


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

def running?
  status.eql?(:running)
end

- (Symbol) status

Returns the current status of this job.

Returns:

  • (Symbol)


94
95
96
# File 'lib/dydra/job.rb', line 94

def status
  Dydra::Client.rpc.call('dydra.job.status', uuid).to_sym
end

- (Time) submitted_at

Returns the time when this job was submitted for execution.

Returns:

  • (Time)

Raises:

  • (NotImplementedError)


110
111
112
# File 'lib/dydra/job.rb', line 110

def 
  raise NotImplementedError # TODO
end

- (String) to_s

Returns a string representation of the job UUID.

Returns:

  • (String)


36
37
38
# File 'lib/dydra/job.rb', line 36

def to_s
  uuid
end

- wait!(options = {}, &block) Also known as: wait

This method returns an undefined value.

Waits until this job is done, meanwhile calling the given block at regular intervals.

Parameters:

  • Hash{Symbol (Hash{Symbol => Object} options)

    => Object} options

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :timeout (Float) — default: nil
  • :sleep (Float) — default: 0.5

    how many seconds to sleep before re-polling the job status



132
133
134
135
136
137
138
139
140
# File 'lib/dydra/job.rb', line 132

def wait!(options = {}, &block)
  timeout = options[:timeout] # TODO
  delay   = options[:sleep] || 0.5
  until done?
    yield if block_given?
    sleep delay unless delay.zero?
  end
  self
end