Class: Prdigest::DeliveryCheckpointStore::Session
- Inherits:
-
Object
- Object
- Prdigest::DeliveryCheckpointStore::Session
- Defined in:
- lib/prdigest/delivery_checkpoint_store.rb
Instance Method Summary collapse
- #accept(index) ⇒ Object
- #begin_attempt(index) ⇒ Object
- #chunks ⇒ Object
- #completed? ⇒ Boolean
- #delivery(failed_chunk: nil) ⇒ Object
-
#initialize(path:, data:) ⇒ Session
constructor
A new instance of Session.
- #next_chunk ⇒ Object
- #reject(index, kind:, message:, permanent:) ⇒ Object
Constructor Details
#initialize(path:, data:) ⇒ Session
Returns a new instance of Session.
15 16 17 18 |
# File 'lib/prdigest/delivery_checkpoint_store.rb', line 15 def initialize(path:, data:) @path = path @data = data end |
Instance Method Details
#accept(index) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/prdigest/delivery_checkpoint_store.rb', line 38 def accept(index) require_in_flight!(index) @data["next_chunk"] = index + 1 @data["in_flight"] = nil @data["status"] = next_chunk == chunks.length ? "completed" : "pending" @data["permanent_error"] = nil persist! end |
#begin_attempt(index) ⇒ Object
32 33 34 35 36 |
# File 'lib/prdigest/delivery_checkpoint_store.rb', line 32 def begin_attempt(index) require_next_chunk!(index) @data["in_flight"] = { "chunk" => index, "started_at" => } persist! end |
#chunks ⇒ Object
20 21 22 |
# File 'lib/prdigest/delivery_checkpoint_store.rb', line 20 def chunks @data.fetch("chunks") end |
#completed? ⇒ Boolean
28 29 30 |
# File 'lib/prdigest/delivery_checkpoint_store.rb', line 28 def completed? @data.fetch("status") == "completed" end |
#delivery(failed_chunk: nil) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/prdigest/delivery_checkpoint_store.rb', line 63 def delivery(failed_chunk: nil) result = { accepted_chunks: next_chunk, total_chunks: chunks.length, status: @data.fetch("status") } result[:failed_chunk] = failed_chunk unless failed_chunk.nil? result end |
#next_chunk ⇒ Object
24 25 26 |
# File 'lib/prdigest/delivery_checkpoint_store.rb', line 24 def next_chunk @data.fetch("next_chunk") end |
#reject(index, kind:, message:, permanent:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/prdigest/delivery_checkpoint_store.rb', line 47 def reject(index, kind:, message:, permanent:) require_in_flight!(index) @data["in_flight"] = nil if permanent @data["status"] = "blocked" @data["permanent_error"] = { "kind" => kind.to_s, "message" => .to_s, "failed_chunk" => index } else @data["permanent_error"] = nil end persist! end |