public Task Run(IWorkContext context)
        {
            context.Verify(nameof(context)).IsNotNull();
            context = context
                      .WithCreateLogger(nameof(ReceiveMessages))
                      .With(_tag);

            context.Telemetry.Info(context, "Receiving events...");
            _messageCount = 0;

            try
            {
                _sampler.Start();
                using Timer timer = new Timer(x => MetricsOutput(context), null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5));

                Task.WaitAll(new MessageReceiverHost().Run(context, _option.TaskCount, async x => await ReceiveMessage(context, x)));
            }
            catch (Exception ex)
            {
                context.Telemetry.Error(context, "Send failed", ex);
                throw;
            }
            finally
            {
                _sampler.Stop();
                MetricsOutput(context);
            }

            MetricsOutput(context);
            context.Telemetry.Info(context, $"Received {_messageCount} messages");
            return(Task.CompletedTask);
        }
Esempio n. 2
0
        public async Task Run(IWorkContext context)
        {
            context.Verify(nameof(context)).IsNotNull();
            context = context
                      .WithCreateLogger(nameof(SendMessages))
                      .With(_tag);

            context.Telemetry.Info(context, $"Sending messages, Task Count:{_option.TaskCount}, ...");

            await SendMessageToServiceBus(context);

            context.Telemetry.Info(context, "Completed sending messages...");
        }
Esempio n. 3
0
        public async Task Run(IWorkContext context)
        {
            context.Verify(nameof(context)).IsNotNull();
            context = context
                      .WithCreateLogger(nameof(ReceiveEvents))
                      .With(_tag);

            context.Telemetry.Info(context, "Receiving events...");
            _messageCount = 0;

            try
            {
                _sampler.Start();
                using Timer timer = new Timer(x => MetricsOutput(context), null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5));

                // Registers the Event Processor Host and starts receiving messages
                EventProcessorOptions eventOption = EventProcessorOptions.DefaultOptions;
                eventOption.ReceiveTimeout = TimeSpan.FromSeconds(5);

                await _eventReceiverHost.RegisterEventProcessorFactoryAsync(new EventProcessFactory(context, _sampler), eventOption);

                while (!context.CancellationToken.IsCancellationRequested)
                {
                    await Task.Delay(500);
                }
            }
            catch (Exception ex)
            {
                context.Telemetry.Error(context, "Send failed", ex);
                throw;
            }
            finally
            {
                context.Telemetry.Info(context, "Unregister event processing...");

                // Disposes of the Event Processor Host
                await _eventReceiverHost.UnregisterEventProcessorAsync();

                _sampler.Stop();

                MetricsOutput(context);
            }

            MetricsOutput(context);
            context.Telemetry.Info(context, $"Received {_messageCount} messages");
        }
Esempio n. 4
0
        public async Task Run(IWorkContext context)
        {
            context.Verify(nameof(context)).IsNotNull();
            context = context
                      .WithCreateLogger(nameof(SendEvents))
                      .With(_tag);

            context.Telemetry.Info(context, $"Sending events, Task Count:{_option.TaskCount}, ...");

            try
            {
                await SendMessagesToEventHub(context);
            }
            finally
            {
                await _sendEvent.Value.CloseAsync(context);

                _sendEvent.Dispose();
            }

            context.Telemetry.Info(context, "Completed sending events...");
        }
        private async Task RunJobGraph(IWorkContext context)
        {
            context.Telemetry.Verbose(context, $"Enter-{nameof(RunJobGraph)}");
            IWorkContext nodeContext = context.WithNewCv();

            while (true)
            {
                context.CancellationToken.ThrowIfCancellationRequested();

                var nodesToRun = _graph.TopologicalSort(_graphContext);
                if (nodesToRun.Count == 0)
                {
                    context.Telemetry.Verbose(context, $"Exit-{nameof(RunJobGraph)}, no nodes to run");
                    break;
                }

                IList <TNode> nodesToStart;
                lock (_lock)
                {
                    nodesToStart = nodesToRun[0]
                                   .Where(x => !_runningKeys.Contains(x.Key))
                                   .ToList();
                }

                foreach (var node in nodesToStart)
                {
                    if (!node.Active)
                    {
                        context.Telemetry.Verbose(context, $"Skipping node {node.Key} because it not active");

                        lock (_lock)
                        {
                            _graphContext.AddProcessedNodeKey(node.Key);
                        }

                        continue;
                    }

                    Guid jobId;
                    if (_semaphore != null)
                    {
                        await _semaphore.WaitAsync();

                        context.Telemetry.TrackMetric(context, $"{nameof(RunJobGraph)}:Enter-Semaphore-CurrentCount", (double)_semaphore.CurrentCount);
                    }

                    nodeContext = nodeContext
                                  .WithCreateLogger(node.Key.ToString())
                                  .WithIncrement();

                    context.Telemetry.Verbose(context, $"{nameof(RunJobGraph)} Starting job for node {node.Key}, node's cv={nodeContext.Cv}");

                    jobId = await _jobHost.StartJob(nodeContext, node, UpdateCompletionList);

                    context.Telemetry.ActivityStart(context, $"{nameof(RunJobGraph)} Started JobId={jobId.ToString()} for node {node.Key}");

                    lock (_lock)
                    {
                        _runningKeys.Add(node.Key);
                        _processedDict.Add(jobId, node.Key);
                    }
                }

                _jobHost.WaitAny(context);
                context.Telemetry.Verbose(context, $"Task-Completed-{nameof(RunJobGraph)}");
            }

            _jobHost.WaitAll(context);
            context.Telemetry.Verbose(context, $"Completed-{nameof(RunJobGraph)}");
        }