public Task ProcessAsync(JToken argumentToken)
            {
                var args = argumentToken.ToObject <Arguments>();
                ISubscriptionActor actor = _factory.Lookup(new ActorId(args.Subscriptionid));

                return(actor.RunActionAsync(args.Method, args.MethodArguments));
            }
Example #2
0
        public virtual async Task <IActionResult> RetrySubscriptionActionAsync(Guid id, long timestamp)
        {
            DateTime ts = DateTimeOffset.FromUnixTimeSeconds(timestamp).UtcDateTime;

            Data.Models.Subscription subscription = await _context.Subscriptions.Where(sub => sub.Id == id)
                                                    .FirstOrDefaultAsync();

            if (subscription == null)
            {
                return(NotFound());
            }

            SubscriptionUpdateHistoryEntry update = await _context.SubscriptionUpdateHistory
                                                    .Where(u => u.SubscriptionId == id)
                                                    .FirstOrDefaultAsync(u => Math.Abs(EF.Functions.DateDiffSecond(u.Timestamp, ts)) < 1);

            if (update == null)
            {
                return(NotFound());
            }

            if (update.Success)
            {
                return(StatusCode(
                           (int)HttpStatusCode.NotAcceptable,
                           new ApiError("That action was successful, it cannot be retried.")));
            }

            _queue.Post(
                async() =>
            {
                ISubscriptionActor actor = _subscriptionActorFactory.Lookup(new ActorId(subscription.Id));
                await actor.RunActionAsync(update.Method, update.Arguments);
            });

            return(Accepted());
        }