pub struct Operations { /* private fields */ }Expand description
User-visible long work: provided and exported by
QueueModule (it needs DatabaseModule).
use navree_queue::{Operation, Operations};
let op = operations
.start(uow, Operation::new("deals.export").owner(user))
.await?;
operations
.dispatch(uow, &op, ExportDeals { operation: op.id })
.await?;
// The client follows GET /api/operations/{op.id}/events.startstores itpending;dispatchanddispatch_batchqueue its work.- Its job’s
ctx.progress(done, total, note)makes itrunningand records the progress; while the job runs the worker beats its heartbeat everyqueue.operations.heartbeat_secs. - It finishes when its job ends:
succeeded(keeping any result set withcomplete),failed, orcancelled. With a batch it finishes once the batch and its callbacks have run. cancelis cooperative: jobs not started are skipped, running ones getJobCancelledfrom their nextctx.progress.- Every change is broadcast as
operation.updatedonprivate-operations.{id}(when the app has adyn Broadcaster).
Implementations§
Source§impl Operations
impl Operations
Sourcepub fn options(&self) -> &OperationsOptions
pub fn options(&self) -> &OperationsOptions
The options operations run with (queue.operations).
Sourcepub async fn start(
&self,
uow: &Uow,
operation: Operation,
) -> Result<OperationRecord, QueueError>
pub async fn start( &self, uow: &Uow, operation: Operation, ) -> Result<OperationRecord, QueueError>
Stores operation as pending, as part of uow; returns it.
Sourcepub async fn dispatch<J: Job>(
&self,
uow: &Uow,
operation: &OperationRecord,
job: J,
) -> Result<String, QueueError>
pub async fn dispatch<J: Job>( &self, uow: &Uow, operation: &OperationRecord, job: J, ) -> Result<String, QueueError>
Queues job as the work of operation, as part of uow; returns
the job id. The job’s progress reports go to the operation, and the
operation finishes when the job ends. For an
idempotent operation the job is kept so
the watchdog can dispatch it again.
Sourcepub async fn dispatch_batch(
&self,
uow: &Uow,
operation: &OperationRecord,
batch: Batch,
) -> Result<JobBatch, QueueError>
pub async fn dispatch_batch( &self, uow: &Uow, operation: &OperationRecord, batch: Batch, ) -> Result<JobBatch, QueueError>
Dispatches batch as the work of operation, as part of uow
(see Batch::operation): the operation’s progress follows the
batch’s finished jobs, and it finishes once the batch and its
callbacks have run.
Sourcepub async fn find(
&self,
id: Uuid,
) -> Result<Option<OperationRecord>, QueueError>
pub async fn find( &self, id: Uuid, ) -> Result<Option<OperationRecord>, QueueError>
The operation id.
Sourcepub async fn for_owner(
&self,
owner: Uuid,
limit: usize,
) -> Result<Vec<OperationRecord>, QueueError>
pub async fn for_owner( &self, owner: Uuid, limit: usize, ) -> Result<Vec<OperationRecord>, QueueError>
The operations owner started, newest first, at most limit.
Sourcepub async fn progress(
&self,
id: Uuid,
done: u64,
total: u64,
note: impl Into<String>,
) -> Result<Option<OperationRecord>, QueueError>
pub async fn progress( &self, id: Uuid, done: u64, total: u64, note: impl Into<String>, ) -> Result<Option<OperationRecord>, QueueError>
Records progress: the operation becomes running with done of
total and note, and its heartbeat is renewed. A finished
operation does not change. Returns the operation afterwards.
Sourcepub async fn heartbeat(&self, id: Uuid) -> Result<(), QueueError>
pub async fn heartbeat(&self, id: Uuid) -> Result<(), QueueError>
Renews the heartbeat of a pending or running operation (work that runs outside the queue calls this to show it is alive).
Sourcepub async fn complete(
&self,
id: Uuid,
result: impl Serialize,
) -> Result<Option<OperationRecord>, QueueError>
pub async fn complete( &self, id: Uuid, result: impl Serialize, ) -> Result<Option<OperationRecord>, QueueError>
Finishes the operation as succeeded with result (what a front
end needs: a download URL, counts). A finished operation does not
change. Returns the operation afterwards.
Sourcepub async fn fail(
&self,
id: Uuid,
error: impl Into<String>,
) -> Result<Option<OperationRecord>, QueueError>
pub async fn fail( &self, id: Uuid, error: impl Into<String>, ) -> Result<Option<OperationRecord>, QueueError>
Finishes the operation as failed with error, a message for
people. A finished operation does not change.
Sourcepub async fn cancel(
&self,
id: Uuid,
) -> Result<Option<OperationRecord>, QueueError>
pub async fn cancel( &self, id: Uuid, ) -> Result<Option<OperationRecord>, QueueError>
Cancels the operation: it becomes cancelled at once, its batch is
cancelled, its jobs that have not started are skipped, and running
ones stop at their next ctx.progress (cooperative). A finished
operation does not change. Returns the operation afterwards (None
when there is none).
Sourcepub async fn sweep(&self) -> Result<SweepReport, QueueError>
pub async fn sweep(&self) -> Result<SweepReport, QueueError>
The watchdog (command queue:watchdog; schedule it every minute).
For each pending or running operation without a heartbeat for
queue.operations.stale_after_secs:
- a job of it still in the queue means the queue still owns the work (a crashed worker’s reservation is taken over by another): left alone;
- its batch finished: it finishes the way the batch did;
idempotentwith a job: the job is dispatched again (at mostmax_redispatchestimes);- otherwise:
failed, “The operation stopped responding.”.
Each step first claims the operation on its row (it must still be
stale), so sweeps that overlap (two nodes, or the schedule and a
manual queue:watchdog) restart or fail an operation once, and a
heartbeat that arrives during the sweep keeps it alive.
Sourcepub async fn prune(&self, older_than: Duration) -> Result<u64, QueueError>
pub async fn prune(&self, older_than: Duration) -> Result<u64, QueueError>
Deletes the operations that finished more than older_than ago;
returns how many.
Sourcepub async fn can_view(
&self,
principal: &Principal,
operation: &OperationRecord,
) -> Result<bool, BoxError>
pub async fn can_view( &self, principal: &Principal, operation: &OperationRecord, ) -> Result<bool, BoxError>
Whether principal may see operation: its owner, or a holder of
queue.operations.view_permission (operations.view) app-wide or
in the operation’s workspace.
Sourcepub async fn can_cancel(
&self,
principal: &Principal,
operation: &OperationRecord,
) -> Result<bool, BoxError>
pub async fn can_cancel( &self, principal: &Principal, operation: &OperationRecord, ) -> Result<bool, BoxError>
Whether principal may cancel operation: its owner, or a holder
of queue.operations.cancel_permission (operations.cancel)
app-wide or in the operation’s workspace.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Operations
impl !UnwindSafe for Operations
impl Forget for Operations
impl Freeze for Operations
impl Move for Operations
impl Send for Operations
impl Sync for Operations
impl Unpin for Operations
impl UnsafeUnpin for Operations
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more