Background tasks and to-dos

The K.taches registry lists the long operations under way: a campaign scan, document indexing, an import, a workflow run. It is distinct from the workflow engine, which also uses the word task but means something else. This page describes both registries, the bridge pattern, and the to-do panel.

Two registries carry the word task. K.workflows holds automatable tasks, which are also the tools of the AI assistant, described on Workflows and tasks. K.taches holds background tasks, which are operations in progress to display. The two do not overlap.

Declaring a background task

var t = K.taches.demarrer({ id: 'campagne.scan.' + key, titre: { fr: 'Analyse du dossier', en: 'Scanning folder' }, sujet: path, // shown second, under the title determinee: false, // no known progress annulable: false }); t.avancer(0.4, 'Hashing'); // if the task is determinate t.reussir(); // clears itself t.echouer(message); // stays until acknowledged
RuleReason
A task declares annulable only if it can actually stop.A button that cancels nothing is worse than no button.
Only success clears itself.An unread failure would disappear before being seen.
An indeterminate task says so.A bar that advances without a real measure sets a false expectation.
The title carries the short name, the subject the full path.Two simultaneous scans must be told apart without a tooltip.

The bridge pattern

A module that produces long operations does not call the registry itself. It emits its life cycle on the bus, and a small separate file listens and creates the tasks. Producer and registry ignore each other, which makes it possible to add progress reporting to a module without touching its code, and to remove it the same way.

// campaign: the producer emits K.events.emit('campagne.scan.debut', { cle: key, chemin: path }); K.events.emit('campagne.scan.fin', { cle: key, erreur: null }); // taches-pont-campagnes.js: the bridge listens K.whenShellReady(function () { K.events.on('campagne.scan.debut', function (e) { /* K.taches.demarrer */ }); K.events.on('campagne.scan.fin', function (e) { /* reussir or echouer */ }); });

Listeners are installed inside K.whenShellReady, not on file load. Nothing guarantees the registry is loaded before the bridge in the shell batch, and testing K.taches on load would give up silently and never retry.

A guard against a double start is needed: without it, a double click leaves an orphan task that the end event will only close once.

Tasks panel

The panel lists running tasks and unacknowledged failures, with their title, subject and progress where it is known. It offers a cancel button only for tasks that declared one.

The case that made this panel necessary is the campaign scan: the wait occupies the Campaign panel, so on a folder of three hundred files a user who wants to work elsewhere during the scan loses sight of the operation. Progress is therefore shown where it is felt, not only where it was triggered.

To-dos

The to-do feature marks any object in the software as needing attention, with or without a note, and gathers those marks in a single panel: incomplete samples, scripts, projects, chain nodes.

PointBehaviour
Setting a markThrough the object's context menu, aggregated from the menu registry.
Covered typesDeclared in a type registry, one adapter per target.
NoteOptional. A mark without a note is still a mark.
WriteTo the database, outside the signed registry: a to-do mark is not a data change.

Menu contributions go through K.menus, which aggregates every contribution for a given target. A to-do entry therefore appears in the existing menus without any panel being modified. Since the contexts supplied by panels do not all carry an object reference, the to-do feature installs one adapter per target rather than imposing a common field on every panel.

Related pages