我想每天,每週和每月生成發票,並且希望定期發送發票。 每位顧客都有不同的發票設置。如何使用'Actor Reminder'機制來安排服務結構中的任務?
回答
:
你可以這樣註冊的工作。基於優秀的documentation我想出了一個示例應用程序,請參閱我的repo。
你的演員應該實現IRemindable
接口。 要創建一個提醒在一個演員的方法使用:
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"));
對於計劃任務,您可以使用外部機制,如hangfire。
它除了web應用程序之外還執行計劃任務,您可以從其任務儀表板跟蹤任務。有時前,我不知道該怎麼做我自己
RecurringJob.AddOrUpdate(() => SoccerDataFetcher_UpdatePlayersOfTeams(), Cron.Daily);
是遲髮型是一個很好的機制進行調度的任務,但我想用可靠的Actor模型,在服務織物使用的調度機制。 –
@SumeshEs然後你應該刪除asp.net標籤。無論如何,與你的問題無關。 –
@PeterBons Ok會這麼做 –
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));
}
}
}
請提供一個小的描述。 – SilentMonk
- 1. 如何在Windows服務中使用Quartz.Net來安排任務?
- 2. 如何使用Marklogic來安排任務
- 3. 如何有效地安排我的服務中的任務?
- 4. 如何使用python安排任務
- 5. 使用cron安排任務
- 6. 如何安排在C#中使用Windows服務的電子郵件任務?
- 7. 如何安排JBoss任務?
- 8. 使用動態時間安排來安排任務4
- 9. 完成任務的服務結構任務隊列
- 10. 安排任務
- 11. 如何使用schtasks來安排非隱藏任務?
- 12. 如何使用win32_schedule工作類來安排任務
- 13. 使用服務結構的服務體系結構
- 14. 服務結構服務與用戶表示的服務結構參與者
- 15. 我可以定製Azure服務結構虛擬機節點嗎?
- 16. 服務結構如何選擇端口來承載服務?
- 17. 使用GcmNetworkManager在Android中安排任務?
- 18. 在服務結構集羣中使用http服務來服務通信安全嗎?
- 19. 在portlet中安排任務
- 20. 如何在REST服務中使用噴射路徑中的actor?
- 21. 試圖在服務結構上使用服務結構PublishProfiles
- 22. 在android中安排任務
- 23. 如何在C++中安排任務
- 24. 如何在Django中安排任務?
- 25. 如何在django中安排任務?
- 26. 如何在ASP.net中安排任務?
- 27. 在Railo中安排任務
- 28. 如何使用PowerShell安裝此服務結構項目?
- 29. 如何在Perl中的不同時區安排未來任務?
- 30. 如何使用msbuild複製任務指定文件夾結構
謝謝你,我正在檢查你的代碼。 –
太好了,讓我們知道它是否有助於[標記你的問題的答案](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)所以其他人知道他們必須看看還是不行:-) –
到期時間的目的是什麼? –