Observable Task Table

Observable task table is a shared memory table that stores the status of observable tasks. It is used to observe the status of long-running tasks.


Updating Status of Observable Task

Observable tasks can be observed by the ObservableTaskTable service.

The ObservableTask class is used to define the task to be observed. It's callback function needs to return a generator. The generator should yield ObservableTaskStatusUpdate instances to update the status of the task.

$this->observableTaskTable->observe(new ObservableTask( iterableTask: function (): Generator { yield new ObservableTaskStatusUpdate(ObservableTaskStatus::Running, null); Coroutine::sleep(3); yield new ObservableTaskStatusUpdate(ObservableTaskStatus::Finished, null); }, name: 'test', category: 'test_tasks', ));


Observable tasks table is iterable and uses shared memory. It is possible to iterate over it in any process to get the accurate state of currently running tasks.

#[RespondsToHttp( method: RequestMethod::GET, pattern: '/observable_task_table', )] #[Singleton(collection: SingletonCollection::HttpResponder)] final readonly class ObservableTasksDashboard extends HttpResponder { public function __construct( private ObservableTaskTable $observableTaskTable, ) {} public function respond(ServerRequestInterface $request, ResponseInterface $response): HttpInterceptableInterface { return new TwigTemplate('observable_task_table.twig',[ 'observableTaskTable' => $this->observableTaskTable, ]); } }
<table> <thead> <tr> <th>slot</th> <th>status</th> <th>category</th> <th>name</th> <th>last update</th> </tr> </thead> <tbody> {% for slotId, observableTask in observableTaskTable %} <tr> <td>{{ slotId }}</td> <td>{{ observableTask.observableTaskStatusUpdate.status.value }}</td> <td>{{ observableTask.category }}</td> <td>{{ observableTask.name }}</td> <td>{{ observableTask.modifiedAt|intl_format_date(request) }}</td> </tr> {% endfor %} </tbody> </table>
Edit on GitHub