question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Onresume not fires and Workflow remains suspended

See original GitHub issue

Hi,

I created a solution based on the tutorial on https://medium.com/codex/part-6-of-building-workflow-driven-net-applications-with-elsa-2-9b3167c612dd .

At the Updateblockchain step workflow remains suspended.

Source code is DocumentManagement.zip

Thanks…

`

namespace DocumentManagement.Workflows.Activities { [Activity( Category = “Document Management”, Description = “Saves a hash of the specified file onto the blockchain to prevent tampering.” )] public class UpdateBlockchain : Activity { public record UpdateBlockchainContext(string WorkflowInstanceId, string ActivityId, string FileSignature);

    private readonly IBackgroundJobClient _backgroundJobClient;
    private readonly IWorkflowInstanceDispatcher _workflowInstanceDispatcher;

    public UpdateBlockchain(IBackgroundJobClient backgroundJobClient, IWorkflowInstanceDispatcher workflowInstanceDispatcher)
    {
        _backgroundJobClient = backgroundJobClient;
        _workflowInstanceDispatcher = workflowInstanceDispatcher;
    }

    [ActivityInput(
        Label = "File",
        Hint = "The file to store its hash of onto the blockchain. Can be byte[] or Stream.",
        SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid },
        DefaultWorkflowStorageProvider = TransientWorkflowStorageProvider.ProviderName
    )]
    public object File { get; set; } = default!;

    [ActivityOutput(Hint = "The computed file signature as stored on the blockchain.")]
    public string Output { get; set; } = default!;

    /// <summary>
    /// Invoked by Hangfire as a background job.
    /// </summary>
    public async Task SubmitToBlockChainAsync(UpdateBlockchainContext context, CancellationToken cancellationToken)
    {
        // Simulate storing it on an imaginary blockchain out there.
        await Task.Delay(TimeSpan.FromSeconds(15), cancellationToken);

        // Resume the suspended workflow.
        await _workflowInstanceDispatcher.DispatchAsync(new ExecuteWorkflowInstanceRequest(context.WorkflowInstanceId, context.ActivityId, new WorkflowInput(context.FileSignature)), cancellationToken);
    }

    protected override async ValueTask<IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
    {
        // Compute hash.
        var bytes = File is Stream stream ? await stream.ReadBytesToEndAsync() : File is byte[] buffer ? buffer : throw new NotSupportedException();
        var fileSignature = ComputeSignature(bytes);

        // Schedule background work using Hangfire.
        _backgroundJobClient.Enqueue(() => SubmitToBlockChainAsync(new UpdateBlockchainContext(context.WorkflowInstance.Id, context.ActivityId, fileSignature), CancellationToken.None));

        // Suspend the workflow.
        return Suspend();
    }

    protected override IActivityExecutionResult OnResume(ActivityExecutionContext context)
    {
        // When we resume, simply complete this activity.
        var fileSignature = context.GetInput<string>();
        Output = fileSignature;
        return Done();
    }

    private static string ComputeSignature(byte[] bytes)
    {
        using var algorithm = SHA256.Create();
        var hashValue = algorithm.ComputeHash(bytes);
        return Convert.ToBase64String(hashValue);
    }
}

}`

Issue Analytics

  • State:open
  • Created 5 months ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
sfmskywalkercommented, May 10, 2023

I’ll take a look as soon as I can, this issue is on my shortlist for this week.

0reactions
osmankoccommented, Jul 28, 2023

Hello there.

I took a break for workflows for some time. Today i gave another try on this issue, and finally found the problem. The issue is probably lowercase to create job que name is working according to local culture.

execute-workflow-ınstance-request-default

{“WorkerCount”:1,“Queues”:[“default”,“trigger-workflows-request”,“execute-workflow-definition-request-default”,“execute-workflow-ınstance-request-default”],“StartedAt”:“2023-07-28T14:25:49.0071871Z”}

after i addd this line at the top of the Program.cs it worked well.

Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

Read more comments on GitHub >

github_iconTop Results From Across the Web

Some Android devices not firing resume event when back ...
Some Android devices not firing resume event when back from lock PIN -> destroys entire lifecycle after that (CLOSED BECAUSE IS RELATED TO...
Read more >
Fragment onResume() & onPause() is not called on ...
FWIW, my experience is that support library fragments do call onPause and onResume when pushing/popping backstack, but the Android built-in ...
Read more >
The activity lifecycle
An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial...
Read more >
Activity state changes
If a new activity or dialog appears in the foreground, taking focus and completely covering the activity in progress, the covered activity loses ......
Read more >
[Solution] Start Tasker after head unit sleep - XDA Forums
I've simply used tasker with "Display on" event for starting the app I need, turning wifi on, etc. Working flawlessly for cold boot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found