Class: Conductor::Worker::TaskInProgress

Inherits:
Object
  • Object
show all
Defined in:
lib/conductor/worker/task_in_progress.rb

Overview

Return type for long-running tasks When a worker returns TaskInProgress, the task remains in IN_PROGRESS state and Conductor will poll again after callback_after_seconds

Examples:

Long-running task with periodic updates

def execute(task)
  ctx = TaskContext.current

  # Check if we're being polled again
  if ctx.poll_count > 0
    # Check if processing is complete
    if processing_complete?(task.input_data['job_id'])
      return { status: 'completed', result: get_result() }
    end

    # Still processing, check back later
    return TaskInProgress.new(
      callback_after_seconds: 30,
      output: { status: 'processing', progress: get_progress() }
    )
  end

  # First poll - start the long-running job
  job_id = start_long_running_job(task.input_data)

  TaskInProgress.new(
    callback_after_seconds: 60,
    output: { status: 'started', job_id: job_id }
  )
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback_after_seconds: 60, output: nil) ⇒ TaskInProgress

Create a TaskInProgress response

Parameters:

  • callback_after_seconds (Integer) (defaults to: 60)

    Seconds to wait before polling again (default: 60)

  • output (Hash, nil) (defaults to: nil)

    Intermediate output data (optional)



45
46
47
48
# File 'lib/conductor/worker/task_in_progress.rb', line 45

def initialize(callback_after_seconds: 60, output: nil)
  @callback_after_seconds = callback_after_seconds
  @output = output
end

Instance Attribute Details

#callback_after_secondsInteger

Returns Seconds to wait before Conductor polls again.

Returns:

  • (Integer)

    Seconds to wait before Conductor polls again



37
38
39
# File 'lib/conductor/worker/task_in_progress.rb', line 37

def callback_after_seconds
  @callback_after_seconds
end

#outputHash?

Returns Intermediate output data.

Returns:

  • (Hash, nil)

    Intermediate output data



40
41
42
# File 'lib/conductor/worker/task_in_progress.rb', line 40

def output
  @output
end

Instance Method Details

#to_hHash

Convert to hash

Returns:

  • (Hash)


52
53
54
55
56
57
# File 'lib/conductor/worker/task_in_progress.rb', line 52

def to_h
  {
    callback_after_seconds: @callback_after_seconds,
    output: @output
  }
end