focusreactive / focusreactive/payload-plugins

translator: an onCancelled lifecycle callback

Open
#106 0 comments 0 reactions 0 assignees View on GitHub
enhancement translator
Dominant language
TypeScript
Stars
19
Forks
0
Avg merge
16h 54m
Merged PRs (30d)
19

Description

Read against **0.10.1**.

## Problem

There is no `onCancelled` callback. The lifecycle set is `onQueued` / `onCompleted` / `onFailed`, and
`withQueuedNotification` decorates `enqueue` only — so a cancelled job simply stops existing and the
host is never told.

Two paths hit this:

1. **Explicit cancellation.** `POST /translate/cancel {ids}` → `TaskRunner.cancel(taskIds)`, which under
the payload-jobs runner calls `payload.jobs.cancel(...)` and then hard-`payload.delete`s the job
rows. A pending job vanishes silently.
2. **The plugin's own supersede path.** `enqueue` already supersedes per (document, target locale),
cancelling and deleting the prior job. So the plugin cancels jobs on its own initiative and tells
nobody.

`Task.cancelled` does not help: it derives from `error.cancelled` on the job row, and the plugin
deletes the row it just cancelled.

## Why this matters

A host tracking per-document translation state has to model "this run is no longer happening". With no
callback, it has to infer that — we release our own state first and treat the plugin call as
best-effort, which works but means the plugin and the host can disagree about what is in flight,
particularly on the supersede path where the host never asked for a cancellation at all.

## Suggested shape

`onCancelled(document, targetLocale, reason)` where `reason` distinguishes an explicit cancel from a
supersede. Firing it before the job row is deleted would let a host read the row if it needs to.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the POST /translate/cancel path and TaskRunner.cancel, then trace payload.jobs.cancel, payload.delete, enqueue, and withQueuedNotification to understand both cancellation paths. Done means exposing onCancelled(document, targetLocale, reason) for explicit cancellation and superseding, firing it before the job row is deleted so hosts can track that the run has ended.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.