【问题标题】:How to schedule a service to run daily and at specific time using service fabric?如何使用服务结构安排服务在每天和特定时间运行?
【发布时间】:2020-12-01 04:11:29
【问题描述】:

我正在尝试构建一个服务,使其每天在特定时间运行一次,以尽量减少使用服务结构对数据库的多次调用

【问题讨论】:

    标签: azure-service-fabric service-fabric-actor


    【解决方案1】:

    您可以使用Actor reminders

    您需要调用 RegisterReminderAsync。每 24 小时运行一次

    
    var reminderRegistration = await this.RegisterReminderAsync(
            reminderName,
            BitConverter.GetBytes(amountInDollars),
            TimeSpan.FromMinutes(0),    //The amount of time to delay before firing the reminder
            TimeSpan.FromHours(24));    //The time interval between firing of reminders
    
    

    如果您想在特定时间运行,您可以每小时/ x 分钟触发一次,并在该方法中检查 DateTime.UtcNow 是否在正确的窗口中。

    【讨论】:

    • 根据所使用的时间间隔,它是否不可能错过正确的时间,例如,如果它每 5 分钟运行一次,而 DateTime 假设 00:01 是它应该运行的时间并在00:00?
    • 您可以将最后执行日期保持在提醒状态以应对这种情况。
    猜你喜欢
    • 2014-03-28
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 2013-12-21
    相关资源
    最近更新 更多