private async Task NotifyPushAsync(Guid batchId, CancellationToken cancellationToken) { var usageNotification = new UsageNotification(); usageNotification.PartitionId = batchId.ToString(); usageNotification.BatchId = Guid.NewGuid(); var notificationContent = JsonConvert.SerializeObject(usageNotification, Formatting.None); CloudQueueMessage queueMessage = new CloudQueueMessage(notificationContent); var retry = 3; while (retry-- > 0) { try { await this.queue.AddMessageAsync(queueMessage, cancellationToken); BillingEventSource.Current.Info(BillingEventSource.EmptyTrackingId, this, nameof(this.PushBucketAsync), OperationStates.Succeeded, $"Notify usage with PartitionId = {usageNotification.PartitionId}, BatchId = {usageNotification.BatchId}"); return; } catch (Exception ex) { BillingEventSource.Current.Warning(BillingEventSource.EmptyTrackingId, this, nameof(this.PushBucketAsync), OperationStates.FailedNotFaulting, ex.ToString()); await Task.Delay(5 * 1000); } } throw new ApplicationException($"Failed to notify for batch {batchId}"); }
protected override async Task Dispatch(ITransport transport) { Event method = (Event)await transport.ReadInt32(); switch (method) { case Event.UsageNotification: string value = await transport.ReadString(); UsageNotification?.Invoke(value); break; default: throw new ProtocolException("Unknown event identifier"); } }
public ValueTask <int> AddOneAsync(int value) { UsageNotification?.Invoke($"A client wants to compute {value} + 1."); Console.WriteLine($"Compute {value} + 1"); return(new ValueTask <int>(value + 1)); }