I was needing some advice on how to run a method that has a loop and some complex logic in it as a hangfire fire-and-forget task.
My question is: I know how to run a fire-and-forget task in hangfire , but wasn’t sure if the method below would be a good candidate for a task in hangfire.?
I could simply use this call: BackgroundJob.Enqueue(() => SaveMembers(selectedChildMembers)) but I am not sure how hangfire will retry it, and whether it will retry it in case the loop in the method failed in the middle.
public void SaveMembers ( List<ChildMember> selectedChildMembers)
{
foreach (ChildMember member in selectedChildMembers)
{
DAL.UpdateChildMember(member);//database call
DAL.UpdateTiers(member); //database call
foreach(Tier tier in member.Tiers)
{
//database call
DAL.UpdateTierHistory( tier, member.MemberID);
}
//sends out an emai
Email.SendNotification(member.EmailAddress);l
}
}
}