Class: JobWorkflow::WorkflowStatus
- Inherits:
-
Object
- Object
- JobWorkflow::WorkflowStatus
- Defined in:
- lib/job_workflow/workflow_status.rb
Defined Under Namespace
Classes: NotFoundError
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
@rbs! type status_type = :pending | :running | :completed | :failed.
-
#job_class_name ⇒ Object
readonly
: String.
-
#status ⇒ Object
readonly
: status_type.
Class Method Summary collapse
-
.find(job_id) ⇒ Object
: (String) -> WorkflowStatus.
-
.find_by(job_id:) ⇒ Object
: (job_id: String) -> WorkflowStatus?.
-
.from_job_data(data) ⇒ Object
: (Hash[String, untyped]) -> WorkflowStatus.
Instance Method Summary collapse
-
#arguments ⇒ Object
: () -> Arguments.
-
#completed? ⇒ Boolean
: () -> bool.
-
#current_task_name ⇒ Object
: () -> Symbol?.
-
#failed? ⇒ Boolean
: () -> bool.
-
#initialize(context:, job_class_name:, status:) ⇒ WorkflowStatus
constructor
: (context: Context, job_class_name: String, status: status_type) -> void.
-
#job_status ⇒ Object
: () -> JobStatus.
-
#output ⇒ Object
: () -> Output.
-
#pending? ⇒ Boolean
: () -> bool.
-
#running? ⇒ Boolean
: () -> bool.
-
#to_h ⇒ Object
: () -> Hash[Symbol, untyped].
Constructor Details
#initialize(context:, job_class_name:, status:) ⇒ WorkflowStatus
: (context: Context, job_class_name: String, status: status_type) -> void
49 50 51 52 53 |
# File 'lib/job_workflow/workflow_status.rb', line 49 def initialize(context:, job_class_name:, status:) @context = context #: Context @job_class_name = job_class_name #: String @status = status #: Symbol end |
Instance Attribute Details
#context ⇒ Object (readonly)
@rbs!
type status_type = :pending | :running | :completed | :failed
10 11 12 |
# File 'lib/job_workflow/workflow_status.rb', line 10 def context @context end |
#job_class_name ⇒ Object (readonly)
: String
11 12 13 |
# File 'lib/job_workflow/workflow_status.rb', line 11 def job_class_name @job_class_name end |
#status ⇒ Object (readonly)
: status_type
12 13 14 |
# File 'lib/job_workflow/workflow_status.rb', line 12 def status @status end |
Class Method Details
.find(job_id) ⇒ Object
: (String) -> WorkflowStatus
16 17 18 19 20 21 |
# File 'lib/job_workflow/workflow_status.rb', line 16 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:) ⇒ Object
: (job_id: String) -> WorkflowStatus?
24 25 26 27 28 29 |
# File 'lib/job_workflow/workflow_status.rb', line 24 def find_by(job_id:) data = QueueAdapter.current.find_job(job_id) return if data.nil? WorkflowStatus.from_job_data(data) end |
.from_job_data(data) ⇒ Object
: (Hash[String, untyped]) -> WorkflowStatus
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/job_workflow/workflow_status.rb', line 32 def from_job_data(data) job_class_name = data["class_name"] job_class = job_class_name.constantize workflow = job_class._workflow context_data = data["job_workflow_context"] || data["arguments"]&.first&.dig("job_workflow_context") context = if context_data Context.deserialize(context_data.merge("workflow" => workflow)) else Context.from_hash({ workflow: }) end new(context:, job_class_name:, status: data["status"]) end |
Instance Method Details
#arguments ⇒ Object
: () -> Arguments
61 62 63 |
# File 'lib/job_workflow/workflow_status.rb', line 61 def arguments context.arguments end |
#completed? ⇒ Boolean
: () -> bool
81 82 83 |
# File 'lib/job_workflow/workflow_status.rb', line 81 def completed? status == :succeeded end |
#current_task_name ⇒ Object
: () -> Symbol?
56 57 58 |
# File 'lib/job_workflow/workflow_status.rb', line 56 def current_task_name context._task_context.task&.task_name end |
#failed? ⇒ Boolean
: () -> bool
86 87 88 |
# File 'lib/job_workflow/workflow_status.rb', line 86 def failed? status == :failed end |
#job_status ⇒ Object
: () -> JobStatus
71 72 73 |
# File 'lib/job_workflow/workflow_status.rb', line 71 def job_status context.job_status end |
#output ⇒ Object
: () -> Output
66 67 68 |
# File 'lib/job_workflow/workflow_status.rb', line 66 def output context.output end |
#pending? ⇒ Boolean
: () -> bool
91 92 93 |
# File 'lib/job_workflow/workflow_status.rb', line 91 def pending? status == :pending end |
#running? ⇒ Boolean
: () -> bool
76 77 78 |
# File 'lib/job_workflow/workflow_status.rb', line 76 def running? status == :running end |
#to_h ⇒ Object
: () -> Hash[Symbol, untyped]
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/job_workflow/workflow_status.rb', line 96 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 |