Class: ChronoForge::Workflow

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
lib/chrono_forge/workflow.rb

Instance Method Summary collapse

Instance Method Details

#ensure_retryable!Object



48
49
50
51
52
53
# File 'lib/chrono_forge/workflow.rb', line 48

def ensure_retryable!
  return if retryable?

  raise Executor::WorkflowNotRetryableError,
    "Cannot retry workflow(#{key}) in #{state} state. Only stalled or failed workflows can be retried."
end

#executable?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/chrono_forge/workflow.rb', line 39

def executable?
  idle? || running?
end

#job_klassObject



69
70
71
# File 'lib/chrono_forge/workflow.rb', line 69

def job_klass
  job_class.constantize
end

#retry_laterObject



64
65
66
67
# File 'lib/chrono_forge/workflow.rb', line 64

def retry_later(**)
  ensure_retryable!
  job_klass.retry_later(key, **)
end

#retry_nowObject

Re-execute this workflow from its record, without constantizing the job class or re-passing the key. Retryability is validated up front so a non-retryable workflow raises immediately rather than enqueuing a job that would fail in the worker.



59
60
61
62
# File 'lib/chrono_forge/workflow.rb', line 59

def retry_now(**)
  ensure_retryable!
  job_klass.retry_now(key, **)
end

#retryable?Boolean

Only stalled or failed workflows can be re-executed.

Returns:

  • (Boolean)


44
45
46
# File 'lib/chrono_forge/workflow.rb', line 44

def retryable?
  stalled? || failed?
end