Class: DirtyPipeline::Event
- Inherits:
-
Object
- Object
- DirtyPipeline::Event
- Defined in:
- lib/dirty_pipeline/event.rb
Constant Summary collapse
- NEW =
"new".freeze
- START =
"started".freeze
- FAILURE =
"failed".freeze
- ABORT =
"aborted".freeze
- RETRY =
"retry".freeze
- SUCCESS =
"succeeded".freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#tx_id ⇒ Object
readonly
Returns the value of attribute tx_id.
Class Method Summary collapse
Instance Method Summary collapse
- #attempt_retry! ⇒ Object
- #attempts_count ⇒ Object
- #complete(changes, destination) ⇒ Object
-
#initialize(options = {}, data: nil, error: nil) ⇒ Event
constructor
A new instance of Event.
- #link_exception(exception) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(options = {}, data: nil, error: nil) ⇒ Event
Returns a new instance of Event.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dirty_pipeline/event.rb', line 25 def initialize( = {}, data: nil, error: nil) unless .empty? = .to_h data ||= ["data"] error ||= ["error"] end data_hash = data.to_h @tx_id = data_hash.fetch("transaction_uuid") @id = data_hash.fetch("uuid") transition = data_hash.fetch("transition") args = data_hash.fetch("args").to_a @data = { "uuid" => @id, "transaction_uuid" => @tx_id, "transition" => transition, "args" => args, "created_at" => Time.now, "cache" => {}, "attempts_count" => 1, "status" => NEW, }.merge(data_hash) @error = error end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
24 25 26 |
# File 'lib/dirty_pipeline/event.rb', line 24 def data @data end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
24 25 26 |
# File 'lib/dirty_pipeline/event.rb', line 24 def error @error end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
24 25 26 |
# File 'lib/dirty_pipeline/event.rb', line 24 def id @id end |
#tx_id ⇒ Object (readonly)
Returns the value of attribute tx_id.
24 25 26 |
# File 'lib/dirty_pipeline/event.rb', line 24 def tx_id @tx_id end |
Class Method Details
.create(transition, *args, tx_id:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dirty_pipeline/event.rb', line 12 def self.create(transition, *args, tx_id:) new( data: { # FIXME: SecureRandom "uuid" => SecureRandom.uuid, "transaction_uuid" => tx_id, "transition" => transition, "args" => args, } ) end |
Instance Method Details
#attempt_retry! ⇒ Object
82 83 84 85 |
# File 'lib/dirty_pipeline/event.rb', line 82 def attempt_retry! @data["updated_at"] = Time.now @data["attempts_count"] = attempts_count + 1 end |
#attempts_count ⇒ Object
78 79 80 |
# File 'lib/dirty_pipeline/event.rb', line 78 def attempts_count @data["attempts_count"].to_i end |
#complete(changes, destination) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/dirty_pipeline/event.rb', line 87 def complete(changes, destination) @data.merge!( "destination" => destination, "changes" => changes, "updated_at" => Time.now, "status" => SUCCESS, ) end |
#link_exception(exception) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/dirty_pipeline/event.rb', line 69 def link_exception(exception) @error = { "exception" => exception.class.to_s, "exception_message" => exception., "created_at" => Time.now, } failure! end |
#to_h ⇒ Object
51 52 53 |
# File 'lib/dirty_pipeline/event.rb', line 51 def to_h {data: @data, error: @error} end |