Class: JobWorkflow::TaskContext
- Inherits:
-
Object
- Object
- JobWorkflow::TaskContext
- Defined in:
- lib/job_workflow/task_context.rb
Constant Summary collapse
- NULL_VALUE =
: nil
nil
Instance Attribute Summary collapse
-
#dry_run ⇒ Object
readonly
: bool.
-
#index ⇒ Object
readonly
: Integer.
-
#parent_job_id ⇒ Object
readonly
: String?.
-
#retry_count ⇒ Object
readonly
: Integer.
-
#task ⇒ Object
readonly
: Task?.
-
#value ⇒ Object
readonly
: untyped.
Class Method Summary collapse
-
.deserialize(hash) ⇒ Object
: (Hash[String, untyped]) -> TaskContext.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
: () -> bool.
-
#initialize(task: nil, parent_job_id: nil, index: 0, value: nil, retry_count: 0, dry_run: false) ⇒ TaskContext
constructor
: ( ?task: Task?, ?parent_job_id: String?, ?index: Integer, ?value: untyped, ?retry_count: Integer, ?dry_run: bool ) -> void.
-
#serialize ⇒ Object
: () -> Hash[String, untyped].
Constructor Details
#initialize(task: nil, parent_job_id: nil, index: 0, value: nil, retry_count: 0, dry_run: false) ⇒ TaskContext
: (
?task: Task?,
?parent_job_id: String?,
?index: Integer,
?value: untyped,
?retry_count: Integer,
?dry_run: bool
) -> void
36 37 38 39 40 41 42 43 |
# File 'lib/job_workflow/task_context.rb', line 36 def initialize(task: nil, parent_job_id: nil, index: 0, value: nil, retry_count: 0, dry_run: false) # rubocop:disable Metrics/ParameterLists self.task = task self.parent_job_id = parent_job_id self.index = index self.value = value self.retry_count = retry_count self.dry_run = dry_run end |
Instance Attribute Details
#dry_run ⇒ Object
: bool
13 14 15 |
# File 'lib/job_workflow/task_context.rb', line 13 def dry_run @dry_run end |
#index ⇒ Object
: Integer
10 11 12 |
# File 'lib/job_workflow/task_context.rb', line 10 def index @index end |
#parent_job_id ⇒ Object
: String?
9 10 11 |
# File 'lib/job_workflow/task_context.rb', line 9 def parent_job_id @parent_job_id end |
#retry_count ⇒ Object
: Integer
12 13 14 |
# File 'lib/job_workflow/task_context.rb', line 12 def retry_count @retry_count end |
#task ⇒ Object
: Task?
8 9 10 |
# File 'lib/job_workflow/task_context.rb', line 8 def task @task end |
#value ⇒ Object
: untyped
11 12 13 |
# File 'lib/job_workflow/task_context.rb', line 11 def value @value end |
Class Method Details
.deserialize(hash) ⇒ Object
: (Hash[String, untyped]) -> TaskContext
17 18 19 20 21 22 23 24 25 |
# File 'lib/job_workflow/task_context.rb', line 17 def deserialize(hash) new( task: hash["task"], parent_job_id: hash["parent_job_id"], index: hash["index"], value: ActiveJob::Arguments.deserialize([hash["value"]]).first, retry_count: hash.fetch("retry_count", 0) ) end |
Instance Method Details
#enabled? ⇒ Boolean
: () -> bool
46 47 48 |
# File 'lib/job_workflow/task_context.rb', line 46 def enabled? !parent_job_id.nil? end |
#serialize ⇒ Object
: () -> Hash[String, untyped]
51 52 53 54 55 56 57 58 59 |
# File 'lib/job_workflow/task_context.rb', line 51 def serialize { "task_name" => task&.task_name, "parent_job_id" => parent_job_id, "index" => index, "value" => ActiveJob::Arguments.serialize([value]).first, "retry_count" => retry_count } end |