Class: JobWorkflow::WorkflowStatus
- Inherits:
-
Object
- Object
- JobWorkflow::WorkflowStatus
- Defined in:
- lib/job_workflow/workflow_status.rb,
sig/generated/job_workflow/workflow_status.rbs
Defined Under Namespace
Classes: NotFoundError
Instance Attribute Summary collapse
- #completed_task_names ⇒ Array[Symbol] readonly
- #context ⇒ Context readonly
- #job_class_name ⇒ String readonly
- #status ⇒ status_type readonly
Class Method Summary collapse
-
.find(job_id) ⇒ WorkflowStatus
: (String) -> WorkflowStatus.
-
.find_by(job_id:) ⇒ WorkflowStatus?
: (job_id: String) -> WorkflowStatus?.
-
.from_job_data(data) ⇒ WorkflowStatus
: (Hash[String, untyped]) -> WorkflowStatus.
Instance Method Summary collapse
-
#arguments ⇒ Arguments
: () -> Arguments.
-
#completed? ⇒ Boolean
: () -> bool.
-
#current_task_name ⇒ Symbol?
: () -> Symbol?.
-
#failed? ⇒ Boolean
: () -> bool.
-
#initialize(context:, job_class_name:, status:, completed_task_names: []) ⇒ WorkflowStatus
constructor
: ( context: Context, job_class_name: String, status: status_type, ?completed_task_names: Array ) -> void.
-
#job_status ⇒ JobStatus
: () -> JobStatus.
-
#output ⇒ Output
: () -> Output.
-
#pending? ⇒ Boolean
: () -> bool.
-
#running? ⇒ Boolean
: () -> bool.
-
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped].
Constructor Details
#initialize(context:, job_class_name:, status:, completed_task_names: []) ⇒ WorkflowStatus
: ( context: Context, job_class_name: String, status: status_type, ?completed_task_names: Array ) -> void
85 86 87 88 89 90 |
# File 'lib/job_workflow/workflow_status.rb', line 85 def initialize(context:, job_class_name:, status:, completed_task_names: []) @context = context #: Context @job_class_name = job_class_name #: String @status = status #: Symbol @completed_task_names = completed_task_names end |
Instance Attribute Details
#completed_task_names ⇒ Array[Symbol] (readonly)
13 14 15 |
# File 'lib/job_workflow/workflow_status.rb', line 13 def completed_task_names @completed_task_names end |
#context ⇒ Context (readonly)
10 11 12 |
# File 'lib/job_workflow/workflow_status.rb', line 10 def context @context end |
#job_class_name ⇒ String (readonly)
11 12 13 |
# File 'lib/job_workflow/workflow_status.rb', line 11 def job_class_name @job_class_name end |
#status ⇒ status_type (readonly)
12 13 14 |
# File 'lib/job_workflow/workflow_status.rb', line 12 def status @status end |
Class Method Details
.find(job_id) ⇒ WorkflowStatus
: (String) -> WorkflowStatus
17 18 19 20 21 22 |
# File 'lib/job_workflow/workflow_status.rb', line 17 def find(job_id) workflow_status = find_by(job_id:) raise NotFoundError, "Workflow with job_id '#{job_id}' not found" if workflow_status.nil? workflow_status end |
.find_by(job_id:) ⇒ WorkflowStatus?
: (job_id: String) -> WorkflowStatus?
25 26 27 28 29 30 31 |
# File 'lib/job_workflow/workflow_status.rb', line 25 def find_by(job_id:) data = QueueAdapter.current.find_job(job_id) return if data.nil? return if data["class_name"] == JobWorkflow::SubTaskJob.name WorkflowStatus.from_job_data(data) end |
.from_job_data(data) ⇒ WorkflowStatus
: (Hash[String, untyped]) -> WorkflowStatus
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/job_workflow/workflow_status.rb', line 34 def from_job_data(data) job_class_name = data["class_name"] job_class = job_class_name.constantize workflow = job_class._workflow context = context_from_job_data(data, workflow) new( context:, job_class_name:, status: data["status"], completed_task_names: completed_task_names_from_job_data(data) ) end |
Instance Method Details
#arguments ⇒ Arguments
: () -> Arguments
98 99 100 |
# File 'lib/job_workflow/workflow_status.rb', line 98 def arguments context.arguments end |
#completed? ⇒ Boolean
: () -> bool
118 119 120 |
# File 'lib/job_workflow/workflow_status.rb', line 118 def completed? status == :succeeded end |
#current_task_name ⇒ Symbol?
: () -> Symbol?
93 94 95 |
# File 'lib/job_workflow/workflow_status.rb', line 93 def current_task_name context._task_context.task&.task_name end |
#failed? ⇒ Boolean
: () -> bool
123 124 125 |
# File 'lib/job_workflow/workflow_status.rb', line 123 def failed? status == :failed end |
#job_status ⇒ JobStatus
: () -> JobStatus
108 109 110 |
# File 'lib/job_workflow/workflow_status.rb', line 108 def job_status context.job_status end |
#output ⇒ Output
: () -> Output
103 104 105 |
# File 'lib/job_workflow/workflow_status.rb', line 103 def output context.output end |
#pending? ⇒ Boolean
: () -> bool
128 129 130 |
# File 'lib/job_workflow/workflow_status.rb', line 128 def pending? status == :pending end |
#running? ⇒ Boolean
: () -> bool
113 114 115 |
# File 'lib/job_workflow/workflow_status.rb', line 113 def running? status == :running end |
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped]
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/job_workflow/workflow_status.rb', line 133 def to_h { status:, job_class_name:, current_task_name:, arguments: arguments.to_h, output: output.flat_task_outputs.map do |task_output| { task_name: task_output.task_name, each_index: task_output.each_index, data: task_output.data } end } end |