Module: Conflow::Flow::JobHandler

Included in:
Conflow::Flow
Defined in:
lib/conflow/flow/job_handler.rb

Overview

Handles running and finishing jobs

Instance Method Summary collapse

Instance Method Details

#finish(job, result = nil) ⇒ Object

Finishes job, changes its status, assigns result of the job and queues new available jobs

Parameters:

  • job (Conflow::Job)

    job to be marked as finished

  • result (Object) (defaults to: nil)

    result of the job



34
35
36
37
38
39
# File 'lib/conflow/flow/job_handler.rb', line 34

def finish(job, result = nil)
  job.result = result if result.is_a?(Hash) && result.any?
  call_script(Conflow::Redis::CompleteJobScript, job)
  queue_available_jobs
  destroy! if finished?
end

#run(job_class, params: {}, after: []) ⇒ Conflow::Job

Returns enqueued job.

Parameters:

  • job_class (Class)

    Class of the worker which will perform the job

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

    Parameters of the job. They will be passed to Worker#perform block. Defalts to empty hash.

  • after (Conflow::Job|Class|Integer|Array<Conflow::Job,Class,Integer>) (defaults to: [])

    Dependencies of the job. Can be one or more objects of the following classes: Job, Class, Integer

Returns:



13
14
15
16
17
18
19
20
# File 'lib/conflow/flow/job_handler.rb', line 13

def run(job_class, params: {}, after: [])
  job, dependencies = job_builder.call(job_class, params, after)

  call_script(Conflow::Redis::AddJobScript, job, after: dependencies)
  queue_available_jobs

  job
end

#start(job) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Starts the job - resolves it’s promises. It’s called by Worker before it yields parameters

Parameters:

  • job (Conflow::Job)

    job that needs to resolve it’s promises

See Also:



27
28
29
# File 'lib/conflow/flow/job_handler.rb', line 27

def start(job)
  call_script(Conflow::Redis::ResolvePromisesScript, job)
end