Lets suppose I have a DAPR actor implementation, which covers a long running operation implemented in single threaded loop. The actor has two responsibilities:
- when actor creates - it also creates the single thread loop
- when actor operation is called - its wakes up the single thread loop
Something like this:
// there can be only one TenantActorWorker
// services.AddTransient<ITenantActorWorker, TenantActorWorker>();
public class TenantActor : Actor
{
private ITenantWorker _worker;
public TenantActor(ActorHost host, ITenantWorker worker)
: base(host)
{
this._worker = worker;
}
public void Process(String tenantId)
{
_worker.WakeUpOrStartFor(tenantId);
}
// ??? how to implement this ??? - there is no "StopActor" like method
public override void StopActor()
{
_worker.Cancel();
}
}
The worker instance is implemented as is, not important here. The important thing is, that I must warn it that the actor becomes deactivated - so also stop processing the long operation . Is there any notitications for actor instance to warn it before deactivates (or worst: being relocated)?
Seems the
protected override Task OnDeactivateAsync()does the trick.