Beispiel #1
0
        private async Task PollCommands()
        {
            try
            {
                if (await _lockProvider.AcquireLock("poll-commands", new CancellationToken()))
                {
                    try
                    {
                        _logger.LogInformation("Polling for scheduled commands");
                        await _persistenceStore.ProcessCommands(new DateTimeOffset(_dateTimeProvider.UtcNow), async (command) =>
                        {
                            switch (command.CommandName)
                            {
                            case ScheduledCommand.ProcessWorkflow:
                                await _queueProvider.QueueWork(command.Data, QueueType.Workflow);
                                break;

                            case ScheduledCommand.ProcessEvent:
                                await _queueProvider.QueueWork(command.Data, QueueType.Event);
                                break;
                            }
                        });
                    }
                    finally
                    {
                        await _lockProvider.ReleaseLock("poll-commands");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
            }
        }
Beispiel #2
0
        private async Task PollCommands()
        {
            var activity = WorkflowActivity.StartPoll("commands");

            try
            {
                if (!_persistenceStore.SupportsScheduledCommands)
                {
                    return;
                }

                if (await _lockProvider.AcquireLock("poll-commands", new CancellationToken()))
                {
                    try
                    {
                        _logger.LogDebug("Polling for scheduled commands");
                        await _persistenceStore.ProcessCommands(new DateTimeOffset(_dateTimeProvider.UtcNow), async (command) =>
                        {
                            switch (command.CommandName)
                            {
                            case ScheduledCommand.ProcessWorkflow:
                                await _queueProvider.QueueWork(command.Data, QueueType.Workflow);
                                break;

                            case ScheduledCommand.ProcessEvent:
                                await _queueProvider.QueueWork(command.Data, QueueType.Event);
                                break;
                            }
                        });
                    }
                    finally
                    {
                        await _lockProvider.ReleaseLock("poll-commands");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                activity?.RecordException(ex);
            }
            finally
            {
                activity?.Dispose();
            }
        }