You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm really struggling with the simple task of resuming a bookmark in a simple standlone console app.
Every bit of documentation and other reference material is out of date as everything is marks as "obsolete" or "deprecated".
I'm running a simple console application that loads a JSON workflow. Is this scenario no longer supported?
The reason I ask is that all the methods now are pointing towards an undocumented IWorkflowClient class that doesn't appear to support loading a workflow from a JSON definition.
If I try to use the old WorkflowRunner then a majority of methods are flagged as deprecated (many specifically referencing the magic workflowruntime.cerateClientAsync as the new preferred option. But this seems exclusively geared towards a full elsa server (which is not currently part of my use case).
I don't know the "official" way but, we use IBookmarkQueue but i can imaging that this doesn't work in the case you don't have a server process running (which processes the queue). I think you have more luck with the following snippet (which uses the IWorkflowClient):
IWorkflowClient client = await workflowRuntime.CreateClientAsync(request.WorkflowInstanceId, cancellationToken).ConfigureAwait(false);
Ok - I've no idea if this is considered correct but it compiles, works and doesn't have any warnings on deprecation or obsolete methods:
// add elsa services
services.AddElsa();
// get reference to service provider
var serviceProvider = services.BuildServiceProvider();
// populate registries
await serviceProvider.PopulateRegistriesAsync();
// import workflow from JSON
var workflowJson = await File.ReadAllTextAsync("workflow-1.json");
// Deserialize json into workflow definition model
var serializer = serviceProvider.GetRequiredService<IActivitySerializer>();
var workflowDefinitionModel = serializer.Deserialize<WorkflowDefinitionModel>(workflowJson);
// map workflow definition model to workflow
var workflowDefinitionMapper = serviceProvider.GetRequiredService<WorkflowDefinitionMapper>();
var workflow = workflowDefinitionMapper.Map(workflowDefinitionModel);
// get reference to workflow registry and register the workflow
var workflowRegistry = serviceProvider.GetRequiredService<IWorkflowRegistry>();
await workflowRegistry.RegisterAsync(workflow);
// optional - get the workflow from the workflow store by name
var populator = serviceProvider.GetRequiredService<IWorkflowDefinitionStorePopulator>();
var store = serviceProvider.GetRequiredService<IWorkflowDefinitionStore>();
var workflowSearch = await store.FindAsync(new WorkflowDefinitionFilter()
{
Name = "Workflow 1"
});
// get reference to workflow runtime
var workflowRuntime = serviceProvider.GetRequiredService<IWorkflowRuntime>();
// create a runtime client and create a workflow instance.
var client = await workflowRuntime.CreateClientAsync();
var test = await client.CreateInstanceAsync(new CreateWorkflowInstanceRequest()
{
Name = workflow.Name,
WorkflowDefinitionHandle = workflow.DefinitionHandle
});
// run the workflow instance - will pause at a bookmark
RunWorkflowInstanceResponse testResult = await client.RunInstanceAsync();
// get the first boommark
var testBookmark = testResult.Bookmarks.FirstOrDefault();
// resume the workflow
testResult = await client.RunInstanceAsync(new RunWorkflowInstanceRequest()
{
BookmarkId = testBookmark!.Id,
});
Activity
RalfvandenBurg commentedon Sep 3, 2025
I don't know the "official" way but, we use IBookmarkQueue but i can imaging that this doesn't work in the case you don't have a server process running (which processes the queue). I think you have more luck with the following snippet (which uses the IWorkflowClient):
IWorkflowClient client = await workflowRuntime.CreateClientAsync(request.WorkflowInstanceId, cancellationToken).ConfigureAwait(false);
adsgreen commentedon Sep 5, 2025
Ok - I've no idea if this is considered correct but it compiles, works and doesn't have any warnings on deprecation or obsolete methods: