Example #1
0
        public async Task Run(Subscription subscription, CancellationToken cancellationToken)
        {
            var query    = _epcisQueries.Single(x => x.Name == subscription.QueryName);
            var response = new PollResponse();


            try
            {
                var pendingRequests = await _subscriptionManager.GetPendingRequestIds(subscription.Id.Value, cancellationToken);

                if (pendingRequests.Any())
                {
                    var parameters = subscription.Parameters.Append(new Model.Queries.QueryParameter {
                        Name = "EQ_requestId", Values = pendingRequests.Select(x => x.ToString()).ToArray()
                    });
                    response = await query.Handle(parameters.ToArray(), cancellationToken);
                }

                response.QueryName      = query.Name;
                response.SubscriptionId = subscription.SubscriptionId;

                await SendSubscriptionResults(subscription, response, cancellationToken);

                await _subscriptionManager.AcknowledgePendingRequests(subscription.Id.Value, pendingRequests, cancellationToken);

                await _subscriptionManager.RegisterSubscriptionTrigger(subscription.Id.Value, SubscriptionResult.Success, default, cancellationToken);