elsa-workflows / elsa-workflows/elsa-core

How to stop a Timer activity after a certain condition is reached, Please help

Open
#4,662 2 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

I'm very new to Elsa workflow, please forgive my mistakes.

I have customized the document approval workflow provided in the documentation for my need. Everything is working fine.

I have a use case now for that I need to send reminders only 3 times and that too on a different time intervals.
Eg. I need to send reminder email for 3 times only
1st time : after 1 hour of sending the approval email
2nd time : after 5 hour
3rd time : after 24 hour

after that again wait for 24 hour, if no response came, Cancel the workflow/make workflow as faulted. No reminders should be sent more than 3 and Workflow should be ended as faulted or cancelled. How to achieve this please help me. I'm very new to this.

Bellow is the code I tried

fork
.When("Remind")
//.Timer(Duration.FromSeconds(0)).WithName("Reminder")
//.IfTrue(CheckReminderLimitReached,context=>context.ThenNamed("Reminder").WorkflowBuilder.Finish())
//.IfFalse(CheckReminderLimitReached)

//.If(context => CheckReminderLimitReached(context))
// .When("true")
// .CancelTimer(context => context.ActivityId).Break()

.Timer(context => GetTimerValue(context)).WithName("Reminder")
.If(context=> CheckReminderLimitReached(context)).When("true").Timer().CancelTimer(context => context.ActivityId).Finish()
.SendEmail(activity => activity
.WithSender(_configuration.GetValue("EmailConfig:From")!)
.WithRecipient(context => context.GetVariable("Approval")!.email_to!)
.WithCcRecipients(context => GetRecipientList(context))
.WithSubject(context => $"{context.GetVariable("Approval")!.email_subject}")
.WithAttachments(context => .... rest of the code


Here, GetTimerValue() and CheckReminderLimitReached() are custom methods I have created for my use.

Approach I have used (Not a good approch, But I need like this only): When Approval email is sent, I'm maintaining a counter file in my local storage to track the no of reminders sent (I don't want to store it in DB). GetTimerValue() will check the counter value and based on the 'n'th reminder it is, it will return the expected Duration value for that reminder and increase the counter by 1.

CheckReminderLimitReached() returns a boolean that counter value reached the limit or not.

How can I use this logic to achieve this use case. Please help, I'm stuck here from 5 days.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.