Class: Metaforce::Job

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

Direct Known Subclasses

CRUD, Deploy, Retrieve

Defined Under Namespace

Classes: CRUD, Deploy, Retrieve

Constant Summary collapse

DELAY_START =
1
DELAY_MULTIPLIER =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Job

Public: Instantiate a new job. Doesn’t actually do anything until .perform is called.

Examples

job = Metaforce::Job.new(client)
# => #<Metaforce::Job @id=nil>

Returns self.



26
27
28
29
# File 'lib/metaforce/job.rb', line 26

def initialize(client)
  @_callbacks = Hash.new { |h,k| h[k] = [] }
  @client = client
end

Instance Attribute Details

#idObject (readonly)

Public: The id of the AsyncResult returned from Salesforce for this job.



15
16
17
# File 'lib/metaforce/job.rb', line 15

def id
  @id
end

Class Method Details

.disable_threading!Object



145
146
147
148
149
150
# File 'lib/metaforce/job.rb', line 145

def self.disable_threading!
  ActiveSupport::Deprecation.warn <<-WARNING.strip_heredoc
    Metaforce::Job.disable_threading! is deprecated. Use Metaforce.configuration.threading = false instead.
  WARNING
  Metaforce.configuration.threading = false
end

Instance Method Details

#done?Boolean

Public: Returns true if the job has completed.

Examples

job.done
# => true

Returns true if the job has completed, false otherwise.

Returns:

  • (Boolean)


106
107
108
# File 'lib/metaforce/job.rb', line 106

def done?
  status.done
end

#inspectObject



141
142
143
# File 'lib/metaforce/job.rb', line 141

def inspect
  "#<#{self.class} @id=#{@id.inspect}>"
end

#performObject

Public: Perform the job.

Examples

job = Metaforce::Job.new
job.perform
# => #<Metaforce::Job @id=nil>

Returns self.



40
41
42
43
# File 'lib/metaforce/job.rb', line 40

def perform
  start_heart_beat
  self
end

#started?Boolean

Public: Utility method to determine if .perform has been called yet.

Returns true if @id is set, false otherwise.

Returns:

  • (Boolean)


48
49
50
# File 'lib/metaforce/job.rb', line 48

def started?
  !!@id
end

#stateObject

Public: Returns the state if the job has finished processing.

Examples

job.state
# => 'Completed'

Returns the state of the job.



118
119
120
# File 'lib/metaforce/job.rb', line 118

def state
  status.state
end

#statusObject

Public: Queries the job status from the API.

Examples

job.status
# => { :id => '1234', :done => false, ... }

Returns the AsyncResult (www.salesforce.com/us/developer/docs/api_meta/Content/meta_asyncresult.htm).



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

def status
  @status ||= client.status(id)
end