protected void AddToUncommittedItems(IListBlockItem <TItem> item) { lock (_uncommittedListSyncRoot) { _uncommittedItems.Add(item); } }
protected ProtoListBlockItem Convert(IListBlockItem <TItem> listBlockItem) { return(new ProtoListBlockItem() { LastUpdated = listBlockItem.LastUpdated, ListBlockItemId = listBlockItem.ListBlockItemId, Status = listBlockItem.Status, StatusReason = LimitLength(listBlockItem.StatusReason, _maxStatusReasonLength), Step = listBlockItem.Step }); }
public async Task DiscardItemAsync(IListBlockItem <TItem> item, string reason, byte?step = null) { item.StatusReason = reason; if (step.HasValue) { item.Step = step; } ValidateBlockIsActive(); item.Status = ItemStatus.Discarded; await UpdateItemStatusAsync(item).ConfigureAwait(false); }
protected void AddToUncommittedItems(IListBlockItem <TItem> item) { _uncommittedListSemaphore.Wait(); try { _uncommittedItems.Add(item); } finally { _uncommittedListSemaphore.Release(); } }
protected async Task CommitAsync(string listBlockId, IListBlockItem <TItem> item) { var singleUpdateRequest = new SingleUpdateRequest() { TaskId = new TaskId(_applicationName, _taskName), ListBlockId = listBlockId, ListBlockItem = Convert(item) }; Func <SingleUpdateRequest, Task> actionRequest = _listBlockRepository.UpdateListBlockItemAsync; await RetryService.InvokeWithRetryAsync(actionRequest, singleUpdateRequest).ConfigureAwait(false); }
public void DiscardItem(IListBlockItem <TItem> item, string reason, byte?step = null) { item.StatusReason = reason; if (step.HasValue) { item.Step = step; } ValidateBlockIsActive(); item.Status = ItemStatus.Discarded; UpdateItemStatus(item); }
protected void Commit(string listBlockId, IListBlockItem <TItem> item) { var singleUpdateRequest = new SingleUpdateRequest() { TaskId = new TaskId(_applicationName, _taskName), ListBlockId = listBlockId, ListBlockItem = Convert(item) }; Action <SingleUpdateRequest> actionRequest = _listBlockRepository.UpdateListBlockItem; RetryService.InvokeWithRetry(actionRequest, singleUpdateRequest); }
protected async Task AddAndCommitIfUncommittedCountReachedAsync(IListBlockItem <TItem> item) { await _uncommittedListSemaphore.WaitAsync().ConfigureAwait(false); try { _uncommittedItems.Add(item); if (_uncommittedItems.Count == UncommittedThreshold) { await CommitUncommittedItemsAsync().ConfigureAwait(false); } } finally { _uncommittedListSemaphore.Release(); } }
protected void UpdateItemStatus(IListBlockItem <TItem> item) { switch (ListUpdateMode) { case ListUpdateMode.SingleItemCommit: Commit(ListBlockId, item); break; case ListUpdateMode.BatchCommitAtEnd: AddToUncommittedItems(item); break; case ListUpdateMode.PeriodicBatchCommit: AddToUncommittedItems(item); CommitIfUncommittedCountReached(); break; } }
protected async Task UpdateItemStatusAsync(IListBlockItem <TItem> item) { switch (ListUpdateMode) { case ListUpdateMode.SingleItemCommit: await CommitAsync(ListBlockId, item).ConfigureAwait(false); break; case ListUpdateMode.BatchCommitAtEnd: AddToUncommittedItems(item); break; case ListUpdateMode.PeriodicBatchCommit: await AddAndCommitIfUncommittedCountReachedAsync(item).ConfigureAwait(false); break; } }
private void ProcessJourney(IListBlockItem <Journey> journeyItem) { try { if (journeyItem.Value.DepartureStation.Equals(journeyItem.Value.ArrivalStation)) { journeyItem.Discarded("Discarded due to distance rule"); } else { var insight = ExtractInsight(journeyItem.Value); _notificationService.NotifyUser(insight); journeyItem.Completed(); } } catch (Exception ex) { journeyItem.Failed(ex.ToString()); } }
public async Task ItemCompleteAsync(IListBlockItem <TItem> item) { ValidateBlockIsActive(); item.Status = ItemStatus.Completed; await UpdateItemStatusAsync(item).ConfigureAwait(false); }
private void ProcessJourney(IListBlockItem<Journey> journeyItem) { try { if (journeyItem.Value.DepartureStation.Equals(journeyItem.Value.ArrivalStation)) { journeyItem.Discarded("Discarded due to distance rule"); } else { var insight = ExtractInsight(journeyItem.Value); _notificationService.NotifyUser(insight); journeyItem.Completed(); } } catch(Exception ex) { journeyItem.Failed(ex.ToString()); } }
public void ItemComplete(IListBlockItem <TItem> item) { ValidateBlockIsActive(); item.Status = ItemStatus.Completed; UpdateItemStatus(item); }