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 <SubscriptionActorActionWorkItem>( SubscriptionActorActionWorkItem.GetArguments(subscription.Id, update.Method, update.Arguments) ); return(Accepted()); }
public SubscriptionHistoryItem(SubscriptionUpdateHistoryEntry other, IUrlHelper url, HttpContext context) { SubscriptionId = other.SubscriptionId; Action = other.Action; Success = other.Success; ErrorMessage = other.ErrorMessage; Timestamp = DateTime.SpecifyKind(other.Timestamp, DateTimeKind.Utc); if (!other.Success) { RetryUrl = new UriBuilder { Scheme = "https", Host = context.Request.GetUri().Host, Path = url.Action( nameof(SubscriptionsController.RetrySubscriptionActionAsync), new { id = other.SubscriptionId, timestamp = Timestamp.ToUnixTimeSeconds() }), }.Uri.AbsoluteUri; } }