protected override async Task <Null> RunOrchestration(OrchestrationContext context, CounterOrchestrationInput input, ILogger logger)
        {
            Debug.WriteLine($"Counter: {input.Counter}");

            if (!context.IsReplaying)
            {
                logger.LogInformation("Orchestration started with Input: {input}.", input.Counter);
            }

            await ScheduleTask <Null>(typeof(Task1), new Task1Input()
            {
                Text = "Text passed from Orchestration."
            });

            await ScheduleTask <Null>(typeof(Task2), new Task2Input()
            {
                Number = 2
            });

            Task.Delay(100).Wait();

            input.Counter--;
            if (input.Counter > 0)
            {
                if (!context.IsReplaying)
                {
                    logger.LogInformation("Orchestration will ContinueAsNew.");
                }

                context.ContinueAsNew(input);
            }

            return(new Null());
        }
        public override async Task <int> RunTask(OrchestrationContext context, RecurringOrchestrationInput input)
        {
            var testTasks = context.CreateClient <ITestTasks>();

            if (targetOchestrationInvocationsCount == 0)
            {
                // First time, Reset Generation Count variable.
                await testTasks.ResetGenerationCounter();
            }

            int result = await context.CreateSubOrchestrationInstance <int>(input.TargetOrchestrationType,
                                                                            GetTargetOrchestrationVersion(),
                                                                            input.TargetOrchestrationInstanceId,
                                                                            input.TargetOrchestrationInput);

            await context.CreateTimer(GetNextExecutionTime(context), true, CancellationToken.None);

            if (ShouldRepeatTargetOrchestration())
            {
                context.ContinueAsNew(input);
            }
            else
            {
                // Finally, Reset Generation Count variable.
                await testTasks.ResetGenerationCounter();
            }

            return(result);
        }
Пример #3
0
                public override async Task <int> RunTask(OrchestrationContext context, int currentValue)
                {
                    string operation = await this.WaitForOperation();

                    bool done = false;

                    switch (operation?.ToLowerInvariant())
                    {
                    case "incr":
                        currentValue++;
                        break;

                    case "decr":
                        currentValue--;
                        break;

                    case "end":
                        done = true;
                        break;
                    }

                    if (!done)
                    {
                        context.ContinueAsNew(currentValue);
                    }

                    return(currentValue);
                }
        public override Task <int> RunTask(OrchestrationContext context, int input)
        {
            if (input > 0)
            {
                context.ContinueAsNew(input - 1);
            }

            return(Task.FromResult(input));
        }
            public override async Task <string> RunTask(OrchestrationContext context, string input)
            {
                string result = await context.ScheduleTask <string>(typeof(Activity1));

                if (string.Equals(input, "THROW", StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException("BADFOOD");
                }

                if (string.Equals(input, "DONTTHROW", StringComparison.OrdinalIgnoreCase))
                {
                    // nothing
                }
                else if (string.Equals(input, "WAIT_THROW", StringComparison.OrdinalIgnoreCase))
                {
                    await context.CreateTimer <object>(context.CurrentUtcDateTime.AddSeconds(15), null);

                    throw new InvalidOperationException("BADFOOD");
                }
                else if (string.Equals(input, "WAIT_DONTTHROW", StringComparison.OrdinalIgnoreCase))
                {
                    await context.CreateTimer <object>(context.CurrentUtcDateTime.AddSeconds(15), null);
                }
                else if (string.Equals(input, "WAIT_AND_WAIT_DONTTHROW", StringComparison.OrdinalIgnoreCase))
                {
                    await context.CreateTimer <object>(context.CurrentUtcDateTime.AddSeconds(15), null);

                    await context.CreateTimer <object>(context.CurrentUtcDateTime.AddSeconds(10), null);
                }
                else if (string.Equals(input, "WAIT_NEWGEN", StringComparison.OrdinalIgnoreCase))
                {
                    await context.CreateTimer <object>(context.CurrentUtcDateTime.AddSeconds(5), null);

                    context.ContinueAsNew("WAIT_NEWGEN_STOP");
                }
                else if (string.Equals(input, "WAIT_NEWGEN_STOP", StringComparison.OrdinalIgnoreCase))
                {
                    await context.CreateTimer <object>(context.CurrentUtcDateTime.AddSeconds(5), null);

                    context.ContinueAsNew("DONTTHROW");
                }

                return(result);
            }
Пример #6
0
            public override async Task <int> RunTask(OrchestrationContext context, int numberOfGenerations)
            {
                int count = await context.ScheduleTask <int>(typeof(GenerationSubTask));

                numberOfGenerations--;
                if (numberOfGenerations > 0)
                {
                    context.ContinueAsNew(numberOfGenerations);
                }

                return(count);
            }
        public override async Task <string> RunTask(OrchestrationContext context, string input)
        {
            string result = await context.ScheduleTask <string>(typeof(HelloActivity), input);

            result = input + ":" + result;
            if (counter < 3)
            {
                counter++;
                context.ContinueAsNew(result);
            }

            return(result);
        }
Пример #8
0
            public override async Task <int> RunTask(OrchestrationContext context, int numberOfGenerations)
            {
                int count = await context.ScheduleTask <int>(typeof(GenerationBasicTask));

                numberOfGenerations--;
                if (numberOfGenerations > 0)
                {
                    context.ContinueAsNew(numberOfGenerations);
                }

                // This is a HACK to get unit test up and running.  Should never be done in actual code.
                Result = count;
                return(count);
            }
Пример #9
0
            public override async Task <int> RunTask(OrchestrationContext context, int numberOfGenerations)
            {
                int count = await WaitForSignal();

                signal.WaitOne();
                numberOfGenerations--;
                if (numberOfGenerations > 0)
                {
                    context.ContinueAsNew(numberOfGenerations);
                }

                // This is a HACK to get unit test up and running.  Should never be done in actual code.
                Result = count.ToString();
                return(count);
            }
Пример #10
0
        public override async Task <int> RunTask(OrchestrationContext context, int input)
        {
            if (input > 0)
            {
                var nextIteration = await context.ScheduleTask <int>(SubtractActivity.Name, SubtractActivity.Version, new SubtractActivity.Input
                {
                    LeftValue  = input,
                    RightValue = 1
                });

                context.ContinueAsNew(nextIteration);
            }

            return(input);
        }
        public override async Task <int> RunTask(OrchestrationContext context, int numberOfGenerations)
        {
            var testTasks = context.CreateClient <ITestTasks>();
            int count     = await testTasks.IncrementGenerationCount();

            numberOfGenerations--;
            if (numberOfGenerations > 0)
            {
                context.ContinueAsNew(numberOfGenerations);
            }

            // This is a HACK to get unit test up and running.  Should never be done in actual code.
            Result = count;
            return(count);
        }
        protected override async Task <Null> RunOrchestration(OrchestrationContext context, TweetOrchestrationInput input, ILogger logger)
        {
            var outPut = await context.ScheduleTask <GetTweetTaskOutput>(typeof(GetTweetsTask), getTweetsTaskInput());

            await context.ScheduleTask <Null>(typeof(SwitchOnLightTask), switchOnLightTaskInput(input.LatestTweetId, outPut.LatestTweetId));

            input.LatestTweetId = outPut.LatestTweetId;

            await context.CreateTimer(context.CurrentUtcDateTime.AddMinutes(1), "");


            logger.LogInformation("Orchestration will ContinueAsNew.");
            context.ContinueAsNew(input);

            return(new Null());
        }
Пример #13
0
            public override async Task <string> RunTask(OrchestrationContext context, int numberOfGenerations)
            {
                numberOfGenerations--;
                if (numberOfGenerations > 0)
                {
                    context.ContinueAsNew(numberOfGenerations);
                }

                if (numberOfGenerations == 1)
                {
                    throw new InvalidOperationException("Test");
                }

                Interlocked.Increment(ref Count);

                return("done");
            }
Пример #14
0
        public override async Task <string> RunTask(OrchestrationContext context, int input)
        {
            if (input == 0)
            {
                context.ContinueAsNew(1);

                return("continue as new");
            }
            else if (input == 1)
            {
                await context.CreateTimer(context.CurrentUtcDateTime, 0);

                return("OK");
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        public async override Task <int> RunTask(OrchestrationContext context, TestOrchestrationInput input)
        {
            Debug.WriteLine($"Orchestration Input: {input.Counter}. IsReplaying: {context.IsReplaying}");

            await context.ScheduleTask <TstNull>(typeof(Tests.TaskOrchestration.CounterOrchestration.Task1), "Input1");

            await context.ScheduleTask <TstNull>(typeof(Task2), "Input1");

            Task.Delay(100).Wait();

            input.Counter--;
            if (input.Counter > 0)
            {
                Debug.WriteLine($"ContinueAsNew {input.Counter}");
                context.ContinueAsNew(input);
            }

            return(input.Counter);
        }
        public override async Task <int> RunTask(OrchestrationContext context, DriverOrchestrationData data)
        {
            var results = new List <Task <int> >();
            var i       = 0;

            for (; i < data.NumberOfParallelTasks; i++)
            {
                results.Add(context.CreateSubOrchestrationInstance <int>(typeof(TestOrchestration), data.SubOrchestrationData));
            }

            int[] counters = await Task.WhenAll(results.ToArray());

            int result = counters.Max();

            if (data.NumberOfIteration > 1)
            {
                data.NumberOfIteration--;
                context.ContinueAsNew(data);
            }

            return(result);
        }
Пример #17
0
            public async override Task <string> RunTask(OrchestrationContext context, string input)
            {
                var message = await tcs.Task;

                if (message == "stop")
                {
                    return($"{input} is done");
                }
                else
                {
                    // send a message back to the sender
                    var senderInstance = new OrchestrationInstance()
                    {
                        InstanceId = message
                    };
                    context.SendEvent(senderInstance, channelName, $"hi from {input}");

                    // start over to wait for the next message
                    context.ContinueAsNew(input);

                    return("this value is meaningless");
                }
            }
Пример #18
0
 public override async Task <object> RunTask(OrchestrationContext context, object input)
 {
     WasRun = true;
     context.ContinueAsNew("V3", null);
     return(null);
 }
Пример #19
0
        public override async Task <string> Execute(OrchestrationContext innerContext, string serializedInput)
        {
            if (this.operationBatch.Count == 0 && this.lockRequest == null)
            {
                // we are idle after a ContinueAsNew - the batch is empty.
                // Wait for more messages to get here (via extended sessions)
                await this.doneProcessingMessages.Task;
            }

            this.Config.TraceHelper.FunctionStarting(
                this.context.HubName,
                this.context.Name,
                this.context.InstanceId,
                this.Config.GetIntputOutputTrace(serializedInput),
                FunctionType.Entity,
                isReplay: false);

            if (this.NumberEventsToReceive > 0)
            {
                await this.doneProcessingMessages.Task;
            }

            // Commit the effects of this batch, if
            // we have not already run into an internal error
            // (in which case we will abort the batch instead of committing it)
            if (this.context.InternalError == null)
            {
                // try to serialize the updated entity state
                bool writeBackSuccessful = this.context.TryWriteback(out var serializationErrorMessage);

                // Send all buffered outgoing messages
                this.context.SendOutbox(innerContext, writeBackSuccessful, serializationErrorMessage);

                var jstate = JToken.FromObject(this.context.State);

                // continue as new
                innerContext.ContinueAsNew(jstate);
            }

            if (this.context.ErrorsPresent(out var description))
            {
                this.Config.TraceHelper.FunctionFailed(
                    this.context.HubName,
                    this.context.Name,
                    this.context.InstanceId,
                    description,
                    functionType: FunctionType.Entity,
                    isReplay: false);
            }
            else
            {
                this.Config.TraceHelper.FunctionCompleted(
                    this.context.HubName,
                    this.context.Name,
                    this.context.InstanceId,
                    this.Config.GetIntputOutputTrace(this.context.State.EntityState),
                    continuedAsNew: true,
                    functionType: FunctionType.Entity,
                    isReplay: false);
            }

            // The return value is not used.
            return(string.Empty);
        }
Пример #20
0
 public override Task <object> RunTask(OrchestrationContext context, object input)
 {
     WasRun = true;
     context.ContinueAsNew("V3", null);
     return(Task.FromResult <object>(null));
 }
Пример #21
0
 /// <inheritdoc/>
 public override void ContinueAsNew(object input)
 {
     PreUpdateProperties();
     _innerContext.ContinueAsNew(input);
     PostUpdateProperties();
 }
        public override async Task <string> Execute(OrchestrationContext innerContext, string serializedInput)
        {
#if !FUNCTIONS_V1
            // Adding "Tags" to activity allows using App Insights to query current state of entities
            var activity = Activity.Current;
            OrchestrationRuntimeStatus status = OrchestrationRuntimeStatus.Running;

            DurableTaskExtension.TagActivityWithOrchestrationStatus(status, this.context.InstanceId, true);
#endif

            if (this.operationBatch.Count == 0 &&
                this.lockRequest == null &&
                (this.toBeRescheduled == null || this.toBeRescheduled.Count == 0))
            {
                // we are idle after a ContinueAsNew - the batch is empty.
                // Wait for more messages to get here (via extended sessions)
                await this.doneProcessingMessages.Task;
            }

            if (!this.messageDataConverter.IsDefault)
            {
                innerContext.MessageDataConverter = this.messageDataConverter;
            }

            if (!this.errorDataConverter.IsDefault)
            {
                innerContext.ErrorDataConverter = this.errorDataConverter;
            }

            this.Config.TraceHelper.FunctionStarting(
                this.context.HubName,
                this.context.Name,
                this.context.InstanceId,
                this.Config.GetIntputOutputTrace(serializedInput),
                FunctionType.Entity,
                isReplay: false);

            if (this.NumberEventsToReceive > 0)
            {
                await this.doneProcessingMessages.Task;
            }

            // Commit the effects of this batch, if
            // we have not already run into an internal error
            // (in which case we will abort the batch instead of committing it)
            if (this.context.InternalError == null)
            {
                bool            writeBackSuccessful       = true;
                ResponseMessage serializationErrorMessage = null;

                if (this.RollbackFailedOperations)
                {
                    // the state has already been written back, since it is
                    // done right after each operation.
                }
                else
                {
                    // we are writing back the state here, after executing
                    // the entire batch of operations.
                    writeBackSuccessful = this.context.TryWriteback(out serializationErrorMessage);
                }

                // Reschedule all signals that were received before their time
                this.context.RescheduleMessages(innerContext, this.toBeRescheduled);

                // Send all buffered outgoing messages
                this.context.SendOutbox(innerContext, writeBackSuccessful, serializationErrorMessage);

                var jstate = JToken.FromObject(this.context.State);

                // continue as new
                innerContext.ContinueAsNew(jstate);
            }

            if (this.context.ErrorsPresent(out var description))
            {
                this.Config.TraceHelper.FunctionFailed(
                    this.context.HubName,
                    this.context.Name,
                    this.context.InstanceId,
                    description,
                    functionType: FunctionType.Entity,
                    isReplay: false);
            }
            else
            {
                this.Config.TraceHelper.FunctionCompleted(
                    this.context.HubName,
                    this.context.Name,
                    this.context.InstanceId,
                    this.Config.GetIntputOutputTrace(this.context.State.EntityState),
                    continuedAsNew: true,
                    functionType: FunctionType.Entity,
                    isReplay: false);
            }

            // The return value is not used.
            return(string.Empty);
        }