private async Task RunAsyncInternal(CancellationToken cancellationToken) { IRuntimeStore runtimeStoreClient = ServiceProxy.Create <IRuntimeStore>(new Uri("fabric:/Prototype/RuntimeStore"), new ServicePartitionKey(0)); ServiceEventSource.Current.ServiceMessage(this.Context, "Service has woken up and executing now."); // Get the tenant id from Runtime store long actorId = await runtimeStoreClient.GetTenantInProgress(); if (actorId == -1) { ServiceEventSource.Current.ServiceMessage(this.Context, "No tenant found to work on."); return; } ServiceEventSource.Current.ServiceMessage(this.Context, "Got tenant {0} to work on.", actorId); ITenantUpdateActor tenantUpdateActor = ActorProxy.Create <ITenantUpdateActor>(new ActorId(actorId), actorServicePath); string currentState = await tenantUpdateActor.GetWorkflowState(); ServiceEventSource.Current.ServiceMessage(this.Context, "Current state of tenant {0} is {1}", actorId, currentState); if (currentState == "Completed")// any terminal { // Move tenant id in runtime store to Terminal Queue ServiceEventSource.Current.ServiceMessage(this.Context, "Moving the tenant to terminal state."); await runtimeStoreClient.TransitionTenantToTerminal(actorId, "Completed"); // Delete actor ServiceEventSource.Current.ServiceMessage(this.Context, "Deleting the actor {0} in service.", actorId); ActorId actorToDelete = new ActorId(actorId); IActorService myActorServiceProxy = ActorServiceProxy.Create(actorServicePath, actorToDelete); await myActorServiceProxy.DeleteActorAsync(actorToDelete, cancellationToken); } else { // TODO Call Execute, mainly to make sure that it is doing work and if needed, move to alerted state /*ServiceEventSource.Current.ServiceMessage(this.Context, "Executing the actor {0} in service.", actorId); * await tenantUpdateActor.Execute();*/ // Re-put to the in-progress queue await runtimeStoreClient.AddTenantInProgress(actorId, "InProgress"); } // If workflow running for long and still, not complete, set to terminal state }
public void Put(int tenantId) { IRuntimeStore helloWorldClient = ServiceProxy.Create <IRuntimeStore>(new Uri("fabric:/Prototype/RuntimeStore"), new ServicePartitionKey(0)); helloWorldClient.AddTenantInProgress(tenantId, "Begin"); }