Ejemplo n.º 1
0
        private async Task ExecuteComponentWork(Guid ingestId, IngestPlanSet.IngestPlanEntry planEntry)
        {
            var eventStore = await GetCaPMEventStore(ingestId);

            var ingestStartedEvent = (await eventStore.GetStoredEvents()).OfType <IngestStarted>().Single();
            var plannedComponentChannelIdentifier = _componentChannelIdentifierRepository.GetChannelIdentifierFor(planEntry.ComponentCode);
            var messageChannel        = _messageSenderFactory.GetChannel <StartComponentWorkCommand>(plannedComponentChannelIdentifier);
            var capmChannelIdentifier = GetCaPMMessageChannelIdentifier();
            var command = new StartComponentWorkCommand()
            {
                IngestId                       = ingestId,
                ComponentCode                  = planEntry.ComponentCode,
                ComponentExecutionId           = planEntry.ComponentExecutionId,
                ComponentSettings              = planEntry.ComponentSettings,
                ComponentResultCallbackChannel = capmChannelIdentifier,
                IngestParameters               = ingestStartedEvent.IngestParameters
            };
            //We would need to do the following two as part of a transaction, if we want to make any guarantees
            await eventStore.StoreEvent(new IngestComponentWorkStartRequested()
            {
                CommandSent = command
            }, _messageSenderFactory.GetChannel <SerializedEvent>(_componentChannelIdentifierRepository.GetChannelIdentifierFor(IngestEventConstants.ChannelIdentifierCode)));

            await messageChannel.Send(command, new MessageSendOptions()
            {
                MessageTimeToLiveInSeconds = planEntry.ExecutionTimeoutInSeconds
            });

            if (planEntry.ExecutionTimeoutInSeconds.HasValue)
            {
                var timeoutMessageChannel = _messageSenderFactory.GetChannel <TimeoutComponentWorkCommand>(capmChannelIdentifier);
                var timeoutMessage        = new TimeoutComponentWorkCommand()
                {
                    ComponentExecutionId           = planEntry.ComponentExecutionId,
                    ComponentTimeoutMessageChannel = capmChannelIdentifier,
                    IngestId = ingestId
                };
                await timeoutMessageChannel.Send(timeoutMessage, new MessageSendOptions()
                {
                    MessageSendDelayInSeconds = planEntry.ExecutionTimeoutInSeconds.Value
                });
            }
        }
Ejemplo n.º 2
0
        private async Task ExecuteComponentCompensation(Guid ingestId, IngestPlanSet.IngestPlanEntry planEntry)
        {
            var eventStore = await GetCaPMEventStore(ingestId);

            var ingestStartedEvent = (await eventStore.GetStoredEvents()).OfType <IngestStarted>().Single();
            var plannedComponentChannelIdentifier = _componentChannelIdentifierRepository.GetChannelIdentifierFor(planEntry.ComponentCode);
            var messageChannel = _messageSenderFactory.GetChannel <StartComponentCompensationCommand>(plannedComponentChannelIdentifier);
            var command        = new StartComponentCompensationCommand()
            {
                IngestId                       = ingestId,
                ComponentCode                  = planEntry.ComponentCode,
                ComponentExecutionId           = planEntry.ComponentExecutionId,
                ComponentSettings              = planEntry.ComponentSettings,
                ComponentResultCallbackChannel = GetCaPMMessageChannelIdentifier(),
                IngestParameters               = ingestStartedEvent.IngestParameters
            };
            //We would need to do the following two as part of a transaction, if we want to make any guarantees
            await eventStore.StoreEvent(new IngestComponentCompensationStartRequested()
            {
                CommandSent = command
            }, _messageSenderFactory.GetChannel <SerializedEvent>(_componentChannelIdentifierRepository.GetChannelIdentifierFor(IngestEventConstants.ChannelIdentifierCode)));

            await messageChannel.Send(command);
        }