Class: LittleGhost::AgentInterruptions::Ticket
- Inherits:
-
Object
- Object
- LittleGhost::AgentInterruptions::Ticket
- Defined in:
- lib/little_ghost/agent_interruptions.rb
Instance Attribute Summary collapse
-
#batch_key ⇒ Object
readonly
Returns the value of attribute batch_key.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#initialize(message, id:, batch_key:, metadata:) ⇒ Ticket
constructor
A new instance of Ticket.
- #reject(error) ⇒ Object
- #resolve(value) ⇒ Object
- #value(cancellation_token:, deadline:) ⇒ Object
Constructor Details
#initialize(message, id:, batch_key:, metadata:) ⇒ Ticket
Returns a new instance of Ticket.
32 33 34 35 36 37 38 39 40 |
# File 'lib/little_ghost/agent_interruptions.rb', line 32 def initialize(, id:, batch_key:, metadata:) @id = id @message = @batch_key = batch_key @metadata = @mutex = Mutex.new @condition = ConditionVariable.new @resolved = false end |
Instance Attribute Details
#batch_key ⇒ Object (readonly)
Returns the value of attribute batch_key.
30 31 32 |
# File 'lib/little_ghost/agent_interruptions.rb', line 30 def batch_key @batch_key end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
30 31 32 |
# File 'lib/little_ghost/agent_interruptions.rb', line 30 def id @id end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
30 31 32 |
# File 'lib/little_ghost/agent_interruptions.rb', line 30 def @message end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
30 31 32 |
# File 'lib/little_ghost/agent_interruptions.rb', line 30 def @metadata end |
Instance Method Details
#reject(error) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/little_ghost/agent_interruptions.rb', line 52 def reject(error) @mutex.synchronize do return if @resolved @error = error @resolved = true @condition.broadcast end end |
#resolve(value) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/little_ghost/agent_interruptions.rb', line 42 def resolve(value) @mutex.synchronize do return if @resolved @value = value @resolved = true @condition.broadcast end end |
#value(cancellation_token:, deadline:) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/little_ghost/agent_interruptions.rb', line 62 def value(cancellation_token:, deadline:) @mutex.synchronize do until @resolved cancellation_token.raise_if_cancelled! raise DeadlineExceededError, "The run deadline was reached" if deadline && Time.now >= deadline timeout = deadline ? [deadline - Time.now, 0.05].min : 0.05 @condition.wait(@mutex, [timeout, 0].max) end cancellation_token.raise_if_cancelled! raise DeadlineExceededError, "The run deadline was reached" if deadline && Time.now >= deadline raise @error if @error @value end end |