Ejemplo n.º 1
0
        public async static Task <ResponseModel> RequestHumanApproval([ActivityTrigger] ResponseModel model,
                                                                      ILogger logger,
                                                                      ExecutionContext context)
        {
            try
            {
                StatusRelay relay = new StatusRelay(JobFunction.GetConfiguration(context));
                await relay.Initialize();

                model.Percent  = 50;
                model.Message  = "Awaiting human approval...";
                model.Value    = "30";
                model.Complete = false;

                model.Url = "https://localhost:44309/home/approval/?id=" + model.Id +
                            "&instanceId=" + model.InstanceId;

                await relay.SendStatusAsync(model);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message, ex);
                logger.LogError(ex.StackTrace);
            }

            return(model);
        }
Ejemplo n.º 2
0
        public async static Task <ResponseModel> JobEscalated([ActivityTrigger] ResponseModel model,
                                                              ILogger logger,
                                                              ExecutionContext context)
        {
            try
            {
                StatusRelay relay = new StatusRelay(JobFunction.GetConfiguration(context));
                await relay.Initialize();

                model.Success  = false;
                model.Complete = true;
                model.Percent  = 100;
                model.Result   = "Job approval ESCALATED";
                model.Message  = "Job approval ESCALATED";

                await relay.SendStatusAsync(model);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message, ex);
                logger.LogError(ex.StackTrace);
            }

            return(model);
        }
        public async static Task <ResponseModel> RunJob([ActivityTrigger] JobModel model, ILogger log,
                                                        ExecutionContext context)
        {
            ResponseModel response = await JobFunction.InternalRun(model, GetJob(model), log, context);

            return(response);
        }
        public async static Task RunFromQueue(
            [ServiceBusTrigger("jobs", Connection = "ServiceBusConnectionString")] string myQueueItem,
            ILogger log,
            ExecutionContext context)
        {
            JobModel model = JsonConvert.DeserializeObject <JobModel>(myQueueItem);

            await JobFunction.InternalRun(model, GetJob(model), log, context);
        }
        public static async Task <ResponseModel> RunDurableJob(
            [OrchestrationTrigger] DurableOrchestrationContext context,
            ILogger log,
            ExecutionContext execContext)
        {
            var config = JobFunction.GetConfiguration(execContext);

            JobModel model = JsonConvert.DeserializeObject <JobModel>(context.GetInput <string>());

            ResponseModel response = await context.CallActivityAsync <ResponseModel>("RunJob", model);

            return(response);
        }
Ejemplo n.º 6
0
        public static async Task <ResponseModel> RunInteractiveJob(
            [OrchestrationTrigger] DurableOrchestrationContext context,
            ILogger log,
            ExecutionContext execContext)
        {
            var config = JobFunction.GetConfiguration(execContext);

            JobModel model = JsonConvert.DeserializeObject <JobModel>(context.GetInput <string>());

            ResponseModel response = await context.CallActivityAsync <ResponseModel>("RunJob", model);

            response.InstanceId = context.InstanceId;

            response = await context.CallActivityAsync <ResponseModel>("RequestHumanApproval", response);

            using (var timeoutCts = new System.Threading.CancellationTokenSource())
            {
                int seconds = Int32.Parse(response.Value);

                DateTime dueTime        = context.CurrentUtcDateTime.AddSeconds(seconds);
                Task     durableTimeout = context.CreateTimer(dueTime, timeoutCts.Token);

                Task countdown = context.CallActivityAsync("Countdown", response);

                Task <ResponseModel> approvalEvent = context.WaitForExternalEvent <ResponseModel>("HumanApprovedEvent");

                if (approvalEvent == await Task.WhenAny(countdown, approvalEvent, durableTimeout))
                {
                    timeoutCts.Cancel();

                    await context.CallActivityAsync("JobApproved", response);
                }
                else
                {
                    await context.CallActivityAsync("JobEscalated", response);
                }
            }

            return(response);
        }
        public static async Task <ResponseModel> RunDurableJobSet(
            [OrchestrationTrigger] DurableOrchestrationContext context,
            ILogger log,
            ExecutionContext execContext)
        {
            var config = JobFunction.GetConfiguration(execContext);

            JobSetModel model = JsonConvert.DeserializeObject <JobSetModel>(context.GetInput <string>());

            ResponseModel response = new ResponseModel()
            {
                Id = model.Id
            };

            foreach (JobModel job in model.Jobs)
            {
                job.Id   = model.Id;
                response = await context.CallActivityAsync <ResponseModel>("RunJob", job);
            }

            return(response);
        }