2017-06-19 22 views

回答

0

你可以這樣註冊的工作。基於優秀的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")); 
+0

謝謝你,我正在檢查你的代碼。 –

+0

太好了,讓我們知道它是否有助於[標記你的問題的答案](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)所以其他人知道他們必須看看還是不行:-) –

+0

到期時間的目的是什麼? –

0

對於計劃任務,您可以使用外部機制,如hangfire

它除了web應用程序之外還執行計劃任務,您可以從其任務儀表板跟蹤任務。有時前,我不知道該怎麼做我自己

RecurringJob.AddOrUpdate(() => SoccerDataFetcher_UpdatePlayersOfTeams(), Cron.Daily); 
+0

是遲髮型是一個很好的機制進行調度的任務,但我想用可靠的Actor模型,在服務織物使用的調度機制。 –

+0

@SumeshEs然後你應該刪除asp.net標籤。無論如何,與你的問題無關。 –

+0

@PeterBons Ok會這麼做 –

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)); 
     } 
    } 
} 
+0

請提供一個小的描述。 – SilentMonk