Skip to content

How to resume bookmark - IWorkflowClient? #6884

Closed

Description

@adsgreen

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).

Is this scenario supported?

I would paste code but I'm essentially just using the https://docs.elsaworkflows.io/getting-started/hello-world console application with the activity creating a bookmark.

Activity

  1. RalfvandenBurg commented on Sep 3, 2025

    @RalfvandenBurg
    Contributor

    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);

            RunWorkflowInstanceRequest runRequest =  new RunWorkflowInstanceRequest()
            {
                Input = [],
                BookmarkId = request.BookMarkId,
                Properties = []
            };
            RunWorkflowInstanceResponse result = await client.RunInstanceAsync(runRequest, cancellationToken).ConfigureAwait(false);
    
  2. adsgreen commented on Sep 5, 2025

    @adsgreen
    Author

    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,
    });
    
  3. locked and limited conversation to collaborators on Oct 4, 2025
  4. converted this issue into a discussion #6947 on Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions