Beispiel #1
0
        public async Task <IActionResult> Post(string queueItemId, [FromBody] string[] requests)
        {
            try
            {
                var  entityId  = new Guid(queueItemId);
                var  queueItem = queueItemRepository.Find(0, 1).Items?.Where(q => q.Id.ToString() == queueItemId).FirstOrDefault();
                long?payload   = 0;

                if (requests.Length == 0 || requests == null)
                {
                    ModelState.AddModelError("Attach", "No files uploaded to attach");
                    return(BadRequest(ModelState));
                }

                foreach (var request in requests)
                {
                    var binaryObject = binaryObjectRepository.Find(null, q => q.Id == Guid.Parse(request))?.Items?.FirstOrDefault();
                    if (binaryObject == null)
                    {
                        ModelState.AddModelError("Save", "No file attached");
                        return(BadRequest(ModelState));
                    }

                    long?size = binaryObject.SizeInBytes;
                    if (size <= 0)
                    {
                        ModelState.AddModelError("File attachment", $"File size of file {binaryObject.Name} cannot be 0");
                        return(BadRequest(ModelState));
                    }

                    //create queue item attachment
                    QueueItemAttachment queueItemAttachment = new QueueItemAttachment()
                    {
                        BinaryObjectId = (Guid)binaryObject.Id,
                        QueueItemId    = Guid.Parse(queueItemId),
                        CreatedBy      = applicationUser?.UserName,
                        CreatedOn      = DateTime.UtcNow,
                        SizeInBytes    = (long)binaryObject.SizeInBytes
                    };
                    repository.Add(queueItemAttachment);
                    payload += queueItemAttachment.SizeInBytes;
                }

                //update queue item payload
                queueItem.PayloadSizeInBytes += (long)payload;
                queueItemRepository.Update(queueItem);
                await webhookPublisher.PublishAsync("QueueItems.QueueItemUpdated", queueItem.Id.ToString(), queueItem.Name).ConfigureAwait(false);

                var queueItemAttachments = repository.Find(null).Items?.Where(q => q.QueueItemId == entityId);
                return(Ok(queueItemAttachments));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Attach", ex.Message);
                return(BadRequest(ModelState));
            }
        }
Beispiel #2
0
        public async Task <QueueItem> Dequeue(string agentId, string queueId)
        {
            string state = QueueItemStateType.New.ToString();

            var item = FindQueueItem(state, queueId);

            if (item != null)
            {
                if (item.ExpireOnUTC != null)
                {
                    while (item.ExpireOnUTC <= DateTime.UtcNow)
                    {
                        item.State        = QueueItemStateType.Failed.ToString();
                        item.StateMessage = $"Queue item {item.Name} is expired.  Moving to next available queue item.";
                        repo.Update(item);

                        item = FindQueueItem(state, queueId);
                        if (item == null)
                        {
                            break;
                        }
                    }
                }

                if (item != null)
                {
                    item.IsLocked           = true;
                    item.LockedOnUTC        = DateTime.UtcNow;
                    item.LockedUntilUTC     = DateTime.UtcNow.AddHours(1);
                    item.State              = QueueItemStateType.InProgress.ToString();
                    item.StateMessage       = null;
                    item.LockedBy           = Guid.Parse(agentId);
                    item.LockTransactionKey = Guid.NewGuid();

                    repo.Update(item);
                }
            }
            return(item);
        }
        public async Task <QueueItem> Dequeue(string agentId, string queueId)
        {
            string newState        = QueueItemStateType.New.ToString();
            string inProgressState = QueueItemStateType.InProgress.ToString();

            UpdateItemsStates(queueId);

            var item = FindQueueItem(newState, queueId);

            if (item != null)
            {
                item.IsLocked           = true;
                item.LockedOnUTC        = DateTime.UtcNow;
                item.LockedUntilUTC     = DateTime.UtcNow.AddHours(1);
                item.State              = QueueItemStateType.InProgress.ToString();
                item.StateMessage       = null;
                item.LockedBy           = Guid.Parse(agentId);
                item.LockTransactionKey = Guid.NewGuid();
                _repo.Update(item);
            }
            return(item);
        }