Ejemplo n.º 1
0
        public static async Task Run([PerperStreamTrigger] PerperStreamContext context,
                                     [Perper("self")] ValidatorKey self,
                                     [PerperStream("inputStream")] IAsyncEnumerable <IHashed <AgentInput> > inputStream,
                                     [PerperStream("outputStream")] IAsyncCollector <AgentOutput> outputStream,
                                     CancellationToken cancellationToken,
                                     ILogger logger)
        {
            await inputStream.ForEachAsync(async input =>
            {
                try
                {
                    var agentContext = await context.CallWorkerAsync <AgentContext <object> >(nameof(RuntimeWorker), new
                    {
                        state   = input.Value.State,
                        sender  = new AgentCapability(input.Value.Sender),
                        message = input.Value.Message
                    }, cancellationToken);

                    await outputStream.AddAsync(new AgentOutput
                    {
                        Previous = input.Hash,
                        State    = agentContext.State,
                        Commands = agentContext.Commands
                    }, cancellationToken);
                }
                catch (Exception e)
                {
                    logger.LogError(e.ToString());
                }
            }, cancellationToken);
        }
Ejemplo n.º 2
0
        public static async Task RunAsync([PerperStreamTrigger] PerperStreamContext context,
                                          [Perper("generator")] IAsyncEnumerable <Data> generator,
                                          [Perper("multiplier")] int multiplier,
                                          [Perper("output")] IAsyncCollector <Data> output,
                                          ILogger logger, CancellationToken cancellationToken)
        {
            var state = await context.FetchStateAsync <List <int> >() ?? new List <int>();

            int counter = 0;

            await foreach (var data in generator.WithCancellation(cancellationToken))
            {
                var value = data.Value;
                logger.LogInformation($"Processor is processing value: {value}");

                var result = await context.CallWorkerAsync <int>(typeof(Worker), new { value, multiplier, state }, cancellationToken);

                state.Add(result);
                await context.UpdateStateAsync(state);

                await output.AddAsync(new Data { Value = result, Description = $"Description {result}" }, cancellationToken);

                counter++;

                if (counter > 4)
                {
                    var iquery = context.Query <Data>(generator).Where(item => item.Value > 100);

                    foreach (var item in iquery.ToList())
                    {
                        logger.LogInformation($"LINQ Query (Where): Received odd item with value: {item.Value}");
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static async Task Run([PerperStreamTrigger] PerperStreamContext context,
                                     [Perper("indices")] int[] indices,
                                     [Perper("output")] IAsyncCollector <Hashtable> output,
                                     ILogger logger, CancellationToken cancellationToken)
        {
            foreach (var index in indices)
            {
                await output.AddAsync(new Hashtable { { "Index", index }, { "Index2", index } }, cancellationToken);
            }

            var result = await context.CallWorkerAsync <string>("Host.Functions.PythonWorker", new
            {
                data = context.GetStream()
            }, cancellationToken);

            logger.LogInformation($"DataFrameGenerator End: {result}");
        }
Ejemplo n.º 4
0
        public static async Task RunAsync([PerperStreamTrigger] PerperStreamContext context,
                                          [Perper("generator")] IAsyncEnumerable <Data> generator,
                                          [Perper("multiplier")] int multiplier,
                                          [Perper("output")] IAsyncCollector <Data> output,
                                          ILogger logger, CancellationToken cancellationToken)
        {
            var state = await context.FetchStateAsync <List <int> >() ?? new List <int>();

            await foreach (var data in generator.WithCancellation(cancellationToken))
            {
                var value = data.Value;
                logger.LogInformation($"Processor is processing value: {value}");

                var result = await context.CallWorkerAsync <string>("Host.Functions.PythonWorker", new
                {
                    value = value.ToString()
                }, cancellationToken);

                state.Add(int.Parse(result));
                await context.UpdateStateAsync(state);

                await output.AddAsync(new Data { Value = int.Parse(result) }, cancellationToken);
            }
        }