public static async Task <bool> OfferOrchestrator([OrchestrationTrigger] DurableOrchestrationContext orchestrationContext, ILogger log) { ProcessInterviewRoundInputModel interviewKit = orchestrationContext.GetInput <ProcessInterviewRoundInputModel>(); log.LogWarning($" >>>>>>>> Offer rolled out waiting for response from candidate. Accept offer using instance {orchestrationContext.InstanceId}"); using (var offerTimeoutTicks = new CancellationTokenSource()) { DateTime expireIn = orchestrationContext.CurrentUtcDateTime.AddSeconds(120); Task offerTimerTask = orchestrationContext.CreateTimer(expireIn, offerTimeoutTicks.Token); Task <bool> offerTaskResult = orchestrationContext.WaitForExternalEvent <bool>("JobOfferAccepted"); Task result = await Task.WhenAny(offerTaskResult, offerTimerTask); if (offerTaskResult == result) { offerTimeoutTicks.Cancel(); return(true); } else { await orchestrationContext.CallActivityAsync <Notification>("JobOfferWithdrawn", interviewKit.JobApplication); } return(false); } }
public static async Task <bool> ReadinessOrchestrator([OrchestrationTrigger] DurableOrchestrationContext orchestrationContext, ILogger log) { ProcessInterviewRoundInputModel interviewKit = orchestrationContext.GetInput <ProcessInterviewRoundInputModel>(); log.LogWarning($" >>>>>>>> ReadinessOrchestrator triggered."); /// Configure this timeout depending on joining date /// Example joining date - 1 day. DateTime expireIn = orchestrationContext.CurrentUtcDateTime.AddSeconds(180); /// Wait from offer accepted -- joining date - 1 day await orchestrationContext.CreateTimer(expireIn, CancellationToken.None); /// Fan out List <Task <bool> > internalTasks = new List <Task <bool> >(); internalTasks.Add(orchestrationContext.CallActivityAsync <bool>("GetWelcomeKitReady", interviewKit.JobApplication)); internalTasks.Add(orchestrationContext.CallActivityAsync <bool>("GetAccountReady", interviewKit.JobApplication)); internalTasks.Add(orchestrationContext.CallActivityAsync <bool>("GetMachineReady", interviewKit.JobApplication)); internalTasks.Add(orchestrationContext.CallActivityAsync <bool>("GetProjectTeamReady", interviewKit.JobApplication)); await Task.WhenAll(internalTasks.ToArray()); return(internalTasks.All(t => t.Result == true)); }
public static async Task <InterviewRoundResult> InterviewRoundOrchestrator([OrchestrationTrigger] DurableOrchestrationContext orchestrationContext, ILogger log) { ProcessInterviewRoundInputModel interviewKit = orchestrationContext.GetInput <ProcessInterviewRoundInputModel>(); log.LogWarning($"Scheduled and conducted interview with {interviewKit.JobApplication.Name}."); log.LogWarning($"Round {interviewKit.RoundNumber} processed, please submit result using instance {orchestrationContext.InstanceId}"); using (var roundTimeoutTicks = new CancellationTokenSource()) { DateTime expireIn = orchestrationContext.CurrentUtcDateTime.AddSeconds(60); Task roundTimerTask = orchestrationContext.CreateTimer(expireIn, roundTimeoutTicks.Token); Task <InterviewRoundResult> roundTaskResult = orchestrationContext.WaitForExternalEvent <InterviewRoundResult>("InterviewRoundResultSubmitted"); Task result = await Task.WhenAny(roundTaskResult, roundTimerTask); if (roundTaskResult == result) { roundTimeoutTicks.Cancel(); return(roundTaskResult.Result); } else { await orchestrationContext.CallActivityAsync <Notification>("DeclineApplication", interviewKit.JobApplication); } return(new InterviewRoundResult() { IsPassed = false }); } }
public static async Task HiringProcessOrchestrator( [OrchestrationTrigger] DurableOrchestrationContext context, ILogger logger) { JobApplication jobApplication = context.GetInput <JobApplication>(); ProcessInterviewRoundInputModel processInterviewRoundOne = new ProcessInterviewRoundInputModel() { JobApplication = jobApplication, RoundNumber = 1, OrchestratorInstanceId = context.InstanceId }; InterviewRoundResult IsRoundOnePassed = await context.CallSubOrchestratorAsync <InterviewRoundResult>("InterviewRoundOrchestrator", processInterviewRoundOne); if (IsRoundOnePassed.IsPassed) { logger.LogWarning($"{jobApplication.Name} has passed round one, scheduling round {processInterviewRoundOne.RoundNumber + 1}."); processInterviewRoundOne.RoundNumber += 1; InterviewRoundResult IsRoundTwoPaased = await context.CallSubOrchestratorAsync <InterviewRoundResult>("InterviewRoundOrchestrator", processInterviewRoundOne); if (IsRoundTwoPaased.IsPassed) { /// Rollout offer /// await context.CallActivityAsync <Notification>("RollOutOffer", processInterviewRoundOne.JobApplication); logger.LogWarning($"Offer rolled out to {processInterviewRoundOne.JobApplication.Name}."); /// Wait for offer approval from candidate /// External Event bool IsOfferAccepted = await context.CallSubOrchestratorAsync <bool>("OfferOrchestrator", processInterviewRoundOne); if (IsOfferAccepted) { /// Fan out processing /// bool finalResult = await context.CallSubOrchestratorAsync <bool>("ReadinessOrchestrator", processInterviewRoundOne.JobApplication); if (finalResult) { logger.LogWarning($"Everything is ready for {processInterviewRoundOne.JobApplication.Name} {finalResult}"); } else { logger.LogWarning($"Not all things are ready for {processInterviewRoundOne.JobApplication.Name} {finalResult}"); } } } } await context.CallActivityAsync <Notification>("DeclineApplication", processInterviewRoundOne.JobApplication); }