Class: Ductwork::Job

Inherits:
Record
  • Object
show all
Defined in:
lib/ductwork/models/job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.enqueue(step, *args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ductwork/models/job.rb', line 12

def self.enqueue(step, *args)
  now = Ductwork::DatabaseClock.now
  job = step.create_job!(
    klass: step.klass,
    started_at: now,
    input_args: JSON.dump({ args: })
  )
  execution = job.executions.create!(
    started_at: now,
    retry_count: 0,
    crash_count: 0
  )

  execution.create_availability!(
    started_at: now,
    pipeline_klass: step.run.pipeline_klass
  )

  Ductwork.logger.info(
    msg: "Job enqueued",
    job_id: job.id,
    job_klass: job.klass
  )

  job
end

Instance Method Details

#return_valueObject



39
40
41
42
43
# File 'lib/ductwork/models/job.rb', line 39

def return_value
  if output_payload.present?
    JSON.parse(output_payload).fetch("payload", nil)
  end
end