public async Task <QueueItem> Commit(Guid queueItemId, Guid transactionKey, string resultJSON) { var item = repo.GetOne(queueItemId); if (item.LockedUntilUTC <= DateTime.UtcNow) { SetNewState(item); repo.Update(item); return(item); } else if (item?.IsLocked == true && item?.LockTransactionKey == transactionKey && item?.LockedUntilUTC >= DateTime.UtcNow) { item.ResultJSON = resultJSON; item.IsLocked = false; item.LockedUntilUTC = null; item.LockedEndTimeUTC = DateTime.UtcNow; item.LockTransactionKey = null; item.LockedBy = null; item.State = QueueItemStateType.Success.ToString(); item.StateMessage = "Queue item transaction has been completed successfully"; repo.Update(item); return(item); } else { throw new Exception("Transaction Key Mismatched or Expired. Cannot Commit."); } }
public async Task <IActionResult> Post(string queueItemId, [FromBody] string[] requests, string driveName = null) { try { var queueItem = _queueItemRepository.GetOne(Guid.Parse(queueItemId)); var queueItemAttachments = _manager.AddFileAttachments(queueItem, requests, driveName); await _webhookPublisher.PublishAsync("QueueItems.QueueItemUpdated", queueItemId, queueItem.Name).ConfigureAwait(false); return(Ok(queueItemAttachments)); } catch (Exception ex) { return(ex.GetActionResult()); } }
public async Task <QueueItem> Commit(Guid transactionKey, string resultJSON) { QueueItem queueItem = await GetQueueItem(transactionKey); if (queueItem == null) { throw new EntityDoesNotExistException("Transaction key cannot be found"); } var item = _repo.GetOne(queueItem.Id.Value); if (item == null) { throw new EntityDoesNotExistException("QueueItem does not exist or you do not have authorized access."); } UpdateItemsStates(item.QueueId.ToString()); if (item.State == "New") { throw new EntityOperationException("Queue item lock time has expired; adding back to queue and trying again"); } if (item.LockedUntilUTC <= DateTime.UtcNow) { SetNewState(item); _repo.Update(item); return(item); } else if (item?.IsLocked == true && item?.LockTransactionKey == transactionKey && item?.LockedUntilUTC >= DateTime.UtcNow) { item.ResultJSON = resultJSON; item.IsLocked = false; item.LockedUntilUTC = null; item.LockedEndTimeUTC = DateTime.UtcNow; item.LockTransactionKey = null; item.LockedBy = null; item.State = QueueItemStateType.Success.ToString(); item.StateMessage = "Queue item transaction has been completed successfully"; _repo.Update(item); return(item); } else { throw new Exception("Transaction Key Mismatched or Expired. Cannot Commit."); } }
public async Task <IActionResult> Put(string queueItemId, string id, [FromForm] IFormFile file) { try { Guid entityId = new Guid(id); Guid queueItemEntityId = new Guid(queueItemId); var queueItem = queueItemRepository.GetOne(queueItemEntityId); var existingAttachment = repository.GetOne(entityId); if (existingAttachment == null) { return(NotFound()); } queueItem.PayloadSizeInBytes -= existingAttachment.SizeInBytes; string binaryObjectId = existingAttachment.BinaryObjectId.ToString(); var binaryObject = binaryObjectRepository.GetOne(Guid.Parse(binaryObjectId)); string organizationId = binaryObject.OrganizationId.ToString(); if (!string.IsNullOrEmpty(organizationId)) { organizationId = binaryObjectManager.GetOrganizationId().ToString(); } if (file == null) { ModelState.AddModelError("Save", "No attachment uploaded"); return(BadRequest(ModelState)); } long size = file == null ? 0 : file.Length; if (size <= 0) { ModelState.AddModelError("File Upload", $"File size of attachment {file.FileName} cannot be 0"); return(BadRequest(ModelState)); } try { existingAttachment.SizeInBytes = file.Length; if (existingAttachment.BinaryObjectId != Guid.Empty && size > 0) { //update attachment file in OpenBots.Server.Web using relative directory string apiComponent = "QueueItemAPI"; binaryObjectManager.Update(file, organizationId, apiComponent, Guid.Parse(binaryObjectId)); await webhookPublisher.PublishAsync("Files.FileUpdated", binaryObject.Id.ToString(), binaryObject.Name).ConfigureAwait(false); } //update queue item payload queueItem.PayloadSizeInBytes += file.Length; queueItemRepository.Update(queueItem); await webhookPublisher.PublishAsync("QueueItems.QueueItemUpdated", queueItem.Id.ToString(), queueItem.Name).ConfigureAwait(false); //update attachment entity await base.PutEntity(id, existingAttachment); return(Ok(existingAttachment)); } catch (Exception ex) { return(ex.GetActionResult()); } } catch (Exception ex) { ModelState.AddModelError("Queue Item Attachment", ex.Message); return(BadRequest(ModelState)); } }