0

I want to create one fabric service which runs at a specific time irrespective of its execution time.

I have created a fabric service with actor reminders and set a period to run every 3 minutes. In the call-back function, I have put a delay of 2 minutes as function processing time.

My code looks like below

 public async Task ReceiveReminderAsync(string reminderName, byte[] state, TimeSpan dueTime, TimeSpan period)
    {
        var current = DateTime.Now;
        if (reminderName.Equals("TaskReminder"))
        {
            Thread.Sleep(2 * 60 * 1000);
            using (var writer = File.AppendText("actor.txt"))
            {
                await writer.WriteLineAsync("1 :: " + current.ToString() + " --> " + DateTime.Now.ToString());
            }
        }
    }
    protected override async Task OnActivateAsync()
    {
        await RegisterReminderAsync("TaskReminder", null, TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(3));

    }

And my logs in Actor.txt looks like below

1 :: 12/28/2021 4:54:52 PM --> 12/28/2021 4:56:52 PM
1 :: 12/28/2021 4:59:52 PM --> 12/28/2021 5:01:52 PM
1 :: 12/28/2021 5:05:52 PM --> 12/28/2021 5:07:52 PM

I want it to run every 3 minutes but it's adding function execution time(2 minutes) and running at every 5 minutes instead.

  • You can refer to a similar issues: [Azure Service Fabric - Fixed time Job](https://stackoverflow.com/questions/69526019/azure-service-fabric-fixed-time-job), [How to schedule a service to run daily and at specific time using service fabric?](https://stackoverflow.com/questions/63359114/how-to-schedule-a-service-to-run-daily-and-at-specific-time-using-service-fabric) and [How to schedule a task in service fabric using 'Ac­tor Remin­der' mechanism?](https://stackoverflow.com/questions/44634818/how-to-schedule-a-task-in-service-fabric-using-actor-reminder-mechanism) – Ecstasy Dec 29 '21 at 06:54
  • 1
    @DeepDave-MT, Yeah, but that doesn't have the answer to my question – Bhumi Kanadiya Dec 29 '21 at 12:22
  • It is how it works. One options is to do this: once the reminder is fired, delete the old one, create a new one set at 3 minutes minus the time it took to process the reminder. – Peter Bons Dec 29 '21 at 14:15
  • @PeterBons Thanks, but Process time is always dynamic. as it's for a demo I have put 2 minutes sleep period as my process time but in real-time it always will be a dynamic time to process logic in there. – Bhumi Kanadiya Dec 29 '21 at 15:37
  • correct, but you can measure the processing time using a stopwatch and calculate the due time of the new reminder. Like 3 minutes - 10 seconds as an example. – Peter Bons Dec 29 '21 at 16:14

0 Answers0