Closed ahitacat closed 1 year ago
echo worker
use RWMutexMap
from internal/sync to create a table of channels to handle current pending work.
yggdrasil
, echo worker running in sleep mode will have the opportunity to cancel that work that has not being finished.Addressed all the change from @jirihnidek comments:
worker/echo/main.go
has changed; could you resolve those conflicts and we'll see if we can revisit this PR again.
CancelMessage(directive string, message_id string, cancel_id string)
@subpop @jirihnidek I have fixed the typos and include your suggestions :smile:
Proposal
Add a new control message of type command that can be used to cancel a work that is already in progress in a worker.
yggd
will receive this command and forward it to the appropriate worker. If this worker implements the cancellation feature it will stop or cancel its work. But it is up to the worker to implement this functionality.This PR also provides an example of how the cancellation message can be implemented in the
echo worker
. It uses a map of synchronized channels to manage the current work, and to send the cancellation message to thegoroutines
that are handle it.This commit adds:
A new command message that can be use to cancel work in progress that is done in the workers.Is send as a command to yggdrasil client. Yggdrasil will send this message to the workers Cancel method.
A new function to the worker, CancelRX. This function will handle the cancel signal in workers side. If it is null the worker doesn't support cancellation of messages.
echo worker implements this cancel function to handle cancellation when it runs in slow mode.
How to test it
Follow the Quickstart steps to set the environment. With the following changes:
Terminal 2 Run the worker with the loop and sleep parameters, this will allow some time to launch the cancel message.
Terminal 4 Run the hello world, that will send a new job to the worker.
In the worker it will appear the
id
of that message:Use the id 67c40762-2343-48ad-9bf1-23a9b98bdacb to send the cancellation message: