Class: ActiveForce::Bulk::Job

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

Constant Summary collapse

STATES =
{
  Open: 'Open',
  UploadComplete: 'UploadComplete',
  InProgress: 'InProgress',
  JobComplete: 'JobComplete',
  Failed: 'Failed',
  Aborted: 'Aborted',
  Deleted: 'Deleted'
}.freeze
OPERATIONS =
%i[insert delete hardDelete update upsert]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation:, object:, id: nil, records: nil) ⇒ Job

Returns a new instance of Job.



21
22
23
24
25
26
27
28
29
# File 'lib/active_force/bulk/job.rb', line 21

def initialize(operation:, object:, id: nil, records: nil)
  @operation = operation.to_sym
  @object = object
  @id = id
  @records = records
  @state = nil
  @content_url = nil
  initialize_state_methods
end

Instance Attribute Details

#content_urlObject

Returns the value of attribute content_url.



6
7
8
# File 'lib/active_force/bulk/job.rb', line 6

def content_url
  @content_url
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/active_force/bulk/job.rb', line 7

def id
  @id
end

#objectObject

Returns the value of attribute object.



6
7
8
# File 'lib/active_force/bulk/job.rb', line 6

def object
  @object
end

#operationObject

Returns the value of attribute operation.



6
7
8
# File 'lib/active_force/bulk/job.rb', line 6

def operation
  @operation
end

#recordsObject (readonly)

Returns the value of attribute records.



6
7
8
# File 'lib/active_force/bulk/job.rb', line 6

def records
  @records
end

#stateObject

Returns the value of attribute state.



6
7
8
# File 'lib/active_force/bulk/job.rb', line 6

def state
  @state
end

Class Method Details

.runObject



48
49
50
51
52
53
54
# File 'lib/active_force/bulk/job.rb', line 48

def self.run(...)
  job = new(...)
  job.create
  job.upload
  job.run
  job
end

Instance Method Details

#abortObject



74
75
76
# File 'lib/active_force/bulk/job.rb', line 74

def abort
  change_state(STATES[:Aborted])
end

#createObject



31
32
33
34
35
36
# File 'lib/active_force/bulk/job.rb', line 31

def create
  request_body = default_job_options.merge(operation: operation, object: object)
  response = client.post("#{ingest_path}/", request_body)
  update_attributes_from(response)
  response
end

#deleteObject



78
79
80
81
# File 'lib/active_force/bulk/job.rb', line 78

def delete
  response = client.delete("#{ingest_path}/#{id}")
  response
end

#failed_resultsObject



56
57
58
# File 'lib/active_force/bulk/job.rb', line 56

def failed_results
  client.get("#{ingest_path}/#{id}/failedResults/")
end

#finished?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/active_force/bulk/job.rb', line 83

def finished?
  job_complete? || failed? || aborted?
end

#infoObject



64
65
66
67
68
# File 'lib/active_force/bulk/job.rb', line 64

def info
  response = client.get("#{ingest_path}/#{id}")
  update_attributes_from(response)
  response
end

#resultObject



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

def result
  ActiveForce::Bulk::JobResult.new(job: self)
end

#runObject



70
71
72
# File 'lib/active_force/bulk/job.rb', line 70

def run
  change_state(STATES[:UploadComplete])
end

#successful_resultsObject



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

def successful_results
  client.get("#{ingest_path}/#{id}/successfulResults/")
end

#uploadObject



38
39
40
41
42
# File 'lib/active_force/bulk/job.rb', line 38

def upload
  headers = {"Content-Type": 'text/csv'}
  response = client.put(content_url, records.to_csv, headers)
  response
end