|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
Interface for durable storage of actions that could not be delivered. More...
#include <offline_queue.hpp>
Public Member Functions | |
| virtual uint64_t | enqueue (std::string payload)=0 |
Appends payload to the queue with no idempotency key. | |
| virtual uint64_t | enqueue (std::string payload, std::string idempotencyKey) |
Appends payload carrying the cross-subsystem idempotencyKey. | |
| virtual std::vector< QueueItem > | drain () const =0 |
| Returns all pending items in enqueue order without removing them. | |
| virtual void | markDone (uint64_t itemId)=0 |
Removes the item identified by itemId. | |
| virtual std::size_t | size () const |
| Returns the number of pending items without removing them. | |
| virtual std::optional< std::size_t > | maxDepth () const |
| Returns the configured maximum depth, or std::nullopt if unbounded. | |
| virtual void | setAttempts (uint64_t itemId, Attempts attempts) |
| Persists an updated attempt count for an item. Default: no-op. | |
| ::morph::async::Completion< uint64_t > | enqueue (::morph::exec::IExecutor &replyExec, std::string payload, std::string idempotencyKey={}) |
Appends payload carrying idempotencyKey on the queue's owner; the new item's id is delivered on replyExec. | |
| ::morph::async::Completion< std::vector< QueueItem > > | drain (::morph::exec::IExecutor &replyExec) const |
Snapshots the pending items on the queue's owner; delivered on replyExec. | |
| ::morph::async::Completion< std::size_t > | size (::morph::exec::IExecutor &replyExec) const |
Counts the pending items on the queue's owner; delivered on replyExec. | |
Protected Member Functions | |
| virtual ::morph::async::Completion< uint64_t > | askEnqueue (::morph::exec::IExecutor &replyExec, std::string payload, std::string idempotencyKey) |
| What enqueue(replyExec, payload, key) asks. The default enqueues where it is called, for an implementation with no owner; one with an owner enqueues there. | |
| virtual ::morph::async::Completion< std::vector< QueueItem > > | askDrain (::morph::exec::IExecutor &replyExec) const |
| What drain(replyExec) asks. The default drains where it is called; one with an owner drains there. | |
| virtual ::morph::async::Completion< std::size_t > | askSize (::morph::exec::IExecutor &replyExec) const |
| What size(replyExec) asks. The default counts where it is called; one with an owner counts there. | |
| virtual void | setIdempotencyKey (uint64_t itemId, std::string idempotencyKey) |
| Stamps an idempotency key onto an already-enqueued item. | |
Interface for durable storage of actions that could not be delivered.
Items accumulate while the system is offline and are replayed by SyncWorker on reconnect. The interface is intentionally minimal so that implementations can range from in-memory (InMemoryOfflineQueue) to SQLite or file-backed stores.
Definition at line 177 of file offline_queue.hpp.
|
nodiscardpure virtual |
Appends payload to the queue with no idempotency key.
| payload | Serialised action to persist. |
Implemented in morph::offline::FileOfflineQueue, morph::offline::InMemoryOfflineQueue, and morph::offline::SqliteOfflineQueue.
|
inlinenodiscardvirtual |
Appends payload carrying the cross-subsystem idempotencyKey.
The key is stored on the resulting QueueItem::idempotencyKey so a replay consumer can dedup this op against ones the journal (or a prior replay) already applied (see QueueItem::idempotencyKey and docs/spec/offline/offline.md).
payload is discarded, the pending item keeps the payload it already had, and no error is raised and nothing is reported to the caller. A caller that re-enqueues a corrected payload under an unchanged key therefore loses the correction — mint a new key when the payload changes.These guarantees are pinned for every shipped implementation by tests/offline_queue_conformance.hpp, which is told which policy each implementation has and asserts it.
The default implementation delegates to enqueue(std::move(payload)) and then stamps the key via setIdempotencyKey, so existing IOfflineQueue implementations keep working without overriding it.
| payload | Serialised action to persist. |
| idempotencyKey | Stable dedup token for the logical op; may be empty. |
Reimplemented in morph::offline::FileOfflineQueue, morph::offline::InMemoryOfflineQueue, and morph::offline::SqliteOfflineQueue.
Definition at line 247 of file offline_queue.hpp.
|
nodiscardpure virtual |
Returns all pending items in enqueue order without removing them.
Items remain in the queue until markDone() is called. It is safe to call drain() multiple times — items survive a crash between drain() and the corresponding markDone() call.
Implemented in morph::offline::FileOfflineQueue, morph::offline::InMemoryOfflineQueue, and morph::offline::SqliteOfflineQueue.
|
pure virtual |
Removes the item identified by itemId.
No-op if itemId is not found.
| itemId | Id returned by the corresponding enqueue() call. |
Implemented in morph::offline::FileOfflineQueue, morph::offline::InMemoryOfflineQueue, and morph::offline::SqliteOfflineQueue.
|
inlinenodiscardvirtual |
Returns the number of pending items without removing them.
Default implementation calls drain().size() — correct but O(n) and allocates a full snapshot vector to answer a size query. Override for an O(1) or index-backed answer.
Reimplemented in morph::offline::FileOfflineQueue, morph::offline::InMemoryOfflineQueue, and morph::offline::SqliteOfflineQueue.
Definition at line 289 of file offline_queue.hpp.
|
inlinenodiscardvirtual |
Returns the configured maximum depth, or std::nullopt if unbounded.
Default: std::nullopt (unbounded) — preserves current behavior for any IOfflineQueue subclass that predates this method.
Reimplemented in morph::offline::FileOfflineQueue, morph::offline::InMemoryOfflineQueue, and morph::offline::SqliteOfflineQueue.
Definition at line 296 of file offline_queue.hpp.
|
inlinevirtual |
Persists an updated attempt count for an item. Default: no-op.
A durable queue overrides this to store the count so the retry budget survives a restart — SyncWorker calls it after every failed replay, and reads the persisted value back through QueueItem::attempts on the next drain() (this run, or after a restart). InMemoryOfflineQueue overrides it to update the in-deque item; a queue that leaves it as the default no-op keeps the pre-existing process-local retry behavior (SyncWorker's own in-memory counter is then always authoritative, since QueueItem::attempts never advances).
| itemId | Id of the item whose attempt count changed. |
| attempts | New cumulative attempt count to persist. Typed, not a bare integer, so a transposed call does not compile — see Attempts for what that silently did before. |
Reimplemented in morph::offline::FileOfflineQueue, morph::offline::InMemoryOfflineQueue, and morph::offline::SqliteOfflineQueue.
Definition at line 312 of file offline_queue.hpp.
|
inlinenodiscard |
Appends payload carrying idempotencyKey on the queue's owner; the new item's id is delivered on replyExec.
The form of enqueue() for a caller that is not on the queue's owner. A full queue rejects the completion with OfflineQueueFullError.
| replyExec | Where the answer is delivered, and where the caller attaches to it. Borrowed: it must outlive the completion. |
| payload | Serialised action to persist. |
| idempotencyKey | Stable dedup token for the logical op; may be empty. |
Definition at line 325 of file offline_queue.hpp.
|
inlinenodiscard |
Snapshots the pending items on the queue's owner; delivered on replyExec.
| replyExec | Where the answer is delivered. Borrowed: it must outlive the completion. |
Definition at line 335 of file offline_queue.hpp.
|
inlinenodiscard |
Counts the pending items on the queue's owner; delivered on replyExec.
| replyExec | Where the answer is delivered. Borrowed: it must outlive the completion. |
Definition at line 345 of file offline_queue.hpp.
|
inlinenodiscardprotectedvirtual |
What enqueue(replyExec, payload, key) asks. The default enqueues where it is called, for an implementation with no owner; one with an owner enqueues there.
| replyExec | Where the answer is delivered. |
| payload | Serialised action to persist. |
| idempotencyKey | Stable dedup token; may be empty. |
Reimplemented in morph::offline::FileOfflineQueue, morph::offline::InMemoryOfflineQueue, and morph::offline::SqliteOfflineQueue.
Definition at line 358 of file offline_queue.hpp.
|
inlinenodiscardprotectedvirtual |
What drain(replyExec) asks. The default drains where it is called; one with an owner drains there.
| replyExec | Where the answer is delivered. |
Reimplemented in morph::offline::FileOfflineQueue, morph::offline::InMemoryOfflineQueue, and morph::offline::SqliteOfflineQueue.
Definition at line 368 of file offline_queue.hpp.
|
inlinenodiscardprotectedvirtual |
What size(replyExec) asks. The default counts where it is called; one with an owner counts there.
| replyExec | Where the answer is delivered. |
Reimplemented in morph::offline::FileOfflineQueue, morph::offline::InMemoryOfflineQueue, and morph::offline::SqliteOfflineQueue.
Definition at line 377 of file offline_queue.hpp.
|
inlineprotectedvirtual |
Stamps an idempotency key onto an already-enqueued item.
Called by the default enqueue(payload, key) overload so implementations that only override the single-argument enqueue still support keys. The default is a no-op (an implementation with no per-item key storage simply drops it); InMemoryOfflineQueue overrides it to record the key.
| itemId | Id of the item to stamp. |
| idempotencyKey | Key to store; ignored by the default no-op. |
Reimplemented in morph::offline::FileOfflineQueue, and morph::offline::SqliteOfflineQueue.
Definition at line 389 of file offline_queue.hpp.