我想每天、每周和每月生成发票,并希望定期发送发票。每个客户都有不同的发票设置。
问问题
1325 次
3 回答
3
前段时间我想知道如何自己做到这一点。基于出色的文档,我提出了一个示例应用程序,请参阅我的repo。
你的actor应该实现这个IRemindable
接口。要创建提醒,请在 actor 方法中使用:
await RegisterReminderAsync(
"MyReminder", // name of the reminder
Encoding.ASCII.GetBytes(message), // byte array with payload (message is a string in my case)
dueTime, // When is the reminder first activated
snoozeTime); // Interval between activations
在您的情况下,将 snoozeTime 设置为一天或一周,以便在每个时段激活提醒。
当到期时间在那里时,该方法ReceiveReminderAsync
被调用:
public Task ReceiveReminderAsync(string reminderName, byte[] state, TimeSpan dueTime, TimeSpan period)
{
ActorEventSource.Current.Message($"Actor recieved reminder {reminderName}.");
...
}
您可以通过提醒的值来判断ReceiveReminderAsync
它是关于哪个提醒的,并且可以使用的内容state
对有效负载进行操作。
要关闭提醒,请使用以下UnregisterReminderAsync
方法:
await UnregisterReminderAsync(GetReminder("MyReminder"));
于 2017-06-19T16:43:29.607 回答
0
internal class InvoiceGenerationActor : Actor, IInvoiceGenerationActor, IRemindable
{
protected override async Task OnActivateAsync()
{
////ActorEventSource.Current.ActorMessage(this, "Actor activated.");
//// The StateManager is this actor's private state store.
//// Data stored in the StateManager will be replicated for high-availability for actors that use volatile or persisted state storage.
//// Any serializable object can be saved in the StateManager.
//// For more information, see https://aka.ms/servicefabricactorsstateserialization
//// return this.StateManager.TryAddStateAsync("count", 0);
////var schedulerDtos = GetSchedulerList();
await base.OnActivateAsync();
ActorEventSource.Current.ActorMessage(this, "Actor activated.");
IActorReminder generationReminderRegistration = await this.RegisterReminderAsync(GenerationRemainder, BitConverter.GetBytes(100), TimeSpan.FromMilliseconds(0), TimeSpan.FromMinutes(10));
////IActorReminder mailReminderRegistration = await this.RegisterReminderAsync(generationRemainder, BitConverter.GetBytes(100), TimeSpan.FromMinutes(1), TimeSpan.FromHours(1));
return;
}
public async Task ReceiveReminderAsync(string reminderName, byte[] context, TimeSpan dueTime, TimeSpan period)
{
if (reminderName.Equals(GenerationRemainder))
{
await GetAllInvoiceSettingAndRegisterNewRemiders();
}
else
{
int solutionPartnerId = BitConverter.ToInt32(context, 0);
var data = await Get("SolutionOwnerInvoiceGeneration/AutomaticInvoiceGeneration/" + solutionPartnerId, "PartnerService");
await UnregisterReminderAsync(GetReminder(reminderName));
}
}
}
于 2017-10-24T18:01:09.390 回答
-1
对于计划任务,您可以使用像hangfire这样的外部机制。
它在 Web 应用程序之外执行计划任务,您可以从其任务仪表板跟踪任务。
您可以注册一份工作,例如:
RecurringJob.AddOrUpdate(() => SoccerDataFetcher_UpdatePlayersOfTeams(), Cron.Daily);
于 2017-06-19T15:51:08.260 回答