public async Task <ActiveRoutineInfo> ScheduleContinuationAsync( ContinueRoutineIntent intent, CancellationToken ct) { var eventData = new RoutineEventData { ServiceId = intent.Continuation.ServiceId, Routine = intent.Continuation.Routine, Callee = intent.Callee, Result = _serializer.SerializeToString(intent.Result) }; var eventEnvelope = new RoutineEventEnvelope { CloudEventsVersion = CloudEventsEnvelope.Version, EventType = DasyncCloudEventsTypes.ContinueRoutine.Name, EventTypeVersion = DasyncCloudEventsTypes.ContinueRoutine.Version, Source = "/" + (intent.Callee?.ServiceId.ServiceName ?? ""), EventID = intent.Id.ToString(), EventTime = DateTimeOffset.Now, EventDeliveryTime = intent.Continuation.ContinueAt?.ToUniversalTime(), ETag = intent.Continuation.Routine.ETag, ContentType = "application/json", Data = CloudEventsSerialization.Serialize(eventData) }; var message = new CloudQueueMessage( JsonConvert.SerializeObject(eventEnvelope, CloudEventsSerialization.JsonSerializerSettings)); TimeSpan?delay = null; if (intent.Continuation.ContinueAt.HasValue) { delay = intent.Continuation.ContinueAt.Value.ToUniversalTime() - DateTime.UtcNow; if (delay <= TimeSpan.Zero) { delay = null; } } while (true) { try { await _transitionsQueue.AddMessageAsync(message, null, delay, ct); break; } catch (QueueDoesNotExistException) { await _transitionsQueue.CreateAsync(ct); } } return(new ActiveRoutineInfo { RoutineId = intent.Continuation.Routine.RoutineId, ETag = intent.Continuation.Routine.ETag }); }
private async Task RunRoutineAsync(RoutineEventEnvelope eventEnvelope, CancellationToken ct) { for (; ;) { var carrier = new TransitionCarrier(this, eventEnvelope); //var transitionInfo = await data.GetTransitionDescriptorAsync(ct); //if (transitionInfo.Type == TransitionType.InvokeRoutine || // transitionInfo.Type == TransitionType.ContinueRoutine) //{ // var routineDescriptor = await data.GetRoutineDescriptorAsync(ct); // if (!string.IsNullOrEmpty(transitionInfo.ETag) && // transitionInfo.ETag != routineDescriptor.ETag) // { // // Ignore - stale duplicate message // return; // } //} try { await _transitionRunner.RunAsync(carrier, ct); break; } catch (ConcurrentRoutineExecutionException) { // re-try continue; } } }
public async Task <ActiveRoutineInfo> ScheduleRoutineAsync( ExecuteRoutineIntent intent, CancellationToken ct) { var pregeneratedRoutineId = intent.Id.ToString(); var routineDescriptor = new RoutineDescriptor { IntentId = intent.Id, MethodId = intent.MethodId, RoutineId = pregeneratedRoutineId }; var eventData = new RoutineEventData { ServiceId = intent.ServiceId, Routine = routineDescriptor, Caller = intent.Caller, Continuation = intent.Continuation, Parameters = _serializer.SerializeToString(intent.Parameters) }; var eventEnvelope = new RoutineEventEnvelope { CloudEventsVersion = CloudEventsEnvelope.Version, EventType = DasyncCloudEventsTypes.InvokeRoutine.Name, EventTypeVersion = DasyncCloudEventsTypes.InvokeRoutine.Version, Source = "/" + (intent.Caller?.ServiceId.ServiceName ?? ""), EventID = intent.Id.ToString(), EventTime = DateTimeOffset.Now, ContentType = "application/json", Data = CloudEventsSerialization.Serialize(eventData) }; var message = new CloudQueueMessage( JsonConvert.SerializeObject(eventEnvelope, CloudEventsSerialization.JsonSerializerSettings)); while (true) { try { await _transitionsQueue.AddMessageAsync(message, null, null, ct); break; } catch (QueueDoesNotExistException) { await _transitionsQueue.CreateAsync(ct); } } return(new ActiveRoutineInfo { RoutineId = pregeneratedRoutineId }); }
public AzureStorageTransitionCarrier( RoutineEventEnvelope eventEnvelope, ICloudTable routinesTable, ICloudTable servicesTable, ISerializer serializer) { _eventEnvelope = eventEnvelope; _routinesTable = routinesTable; _servicesTable = servicesTable; _serializer = serializer; }
private async Task RaiseEventAsync(RoutineEventEnvelope eventEnvelope, CancellationToken ct) { var routineEventData = JsonConvert.DeserializeObject <RoutineEventData>(eventEnvelope.Data); var eventDescriptor = new EventDescriptor { ServiceId = routineEventData.ServiceId, EventId = routineEventData.EventId }; foreach (var eventSubscriberDescriptor in GetEventListeners(eventDescriptor)) { ((FileBasedFabricConnector)Connector).ScheduleRoutineFromEvent(eventSubscriberDescriptor, routineEventData); } }
public Task <ActiveRoutineInfo> ScheduleRoutineAsync( ExecuteRoutineIntent intent, CancellationToken ct) { var pregeneratedRoutineId = intent.Id.ToString(); var routineDescriptor = new RoutineDescriptor { IntentId = intent.Id, MethodId = intent.MethodId, RoutineId = pregeneratedRoutineId }; var eventData = new RoutineEventData { ServiceId = intent.ServiceId, Routine = routineDescriptor, Caller = intent.Caller, Continuation = intent.Continuation, Parameters = _serializer.SerializeToString(intent.Parameters) }; var eventEnvelope = new RoutineEventEnvelope { CloudEventsVersion = CloudEventsEnvelope.Version, EventType = DasyncCloudEventsTypes.InvokeRoutine.Name, EventTypeVersion = DasyncCloudEventsTypes.InvokeRoutine.Version, Source = "/" + (intent.Caller?.ServiceId.ServiceName ?? ""), EventID = intent.Id.ToString(), EventTime = DateTimeOffset.Now, ContentType = "application/json", Data = CloudEventsSerialization.Serialize(eventData) }; var fileName = intent.Id.ToString() + ".json"; var filePath = Path.Combine(_transitionsDirectory, fileName); var content = CloudEventsSerialization.Serialize(eventEnvelope); File.WriteAllText(filePath, content, Encoding.UTF8); var info = new ActiveRoutineInfo { RoutineId = pregeneratedRoutineId }; return(Task.FromResult(info)); }
internal void ScheduleRoutineFromEvent(EventSubscriberDescriptor eventSubscriberDescriptor, RoutineEventData raisedEventData) { var intentId = _idGenerator.NewId(); var pregeneratedRoutineId = intentId.ToString(); var routineDescriptor = new RoutineDescriptor { IntentId = intentId, MethodId = eventSubscriberDescriptor.MethodId, RoutineId = pregeneratedRoutineId }; var eventData = new RoutineEventData { ServiceId = eventSubscriberDescriptor.ServiceId, Routine = routineDescriptor, Caller = new CallerDescriptor { ServiceId = raisedEventData.ServiceId }, Parameters = raisedEventData.Parameters }; var eventEnvelope = new RoutineEventEnvelope { CloudEventsVersion = CloudEventsEnvelope.Version, EventType = DasyncCloudEventsTypes.InvokeRoutine.Name, EventTypeVersion = DasyncCloudEventsTypes.InvokeRoutine.Version, Source = "/" + (raisedEventData.ServiceId?.ServiceName ?? ""), EventID = intentId.ToString(), EventTime = DateTimeOffset.Now, ContentType = "application/json", Data = CloudEventsSerialization.Serialize(eventData) }; var fileName = intentId.ToString() + ".json"; var filePath = Path.Combine(_transitionsDirectory, fileName); var content = CloudEventsSerialization.Serialize(eventEnvelope); File.WriteAllText(filePath, content, Encoding.UTF8); }
public Task PublishEventAsync(RaiseEventIntent intent, CancellationToken ct) { var eventData = new RoutineEventData { ServiceId = intent.ServiceId, EventId = intent.EventId, Parameters = _serializer.SerializeToString(intent.Parameters) }; var eventEnvelope = new RoutineEventEnvelope { CloudEventsVersion = CloudEventsEnvelope.Version, EventType = DasyncCloudEventsTypes.RaiseEvent.Name, EventTypeVersion = DasyncCloudEventsTypes.RaiseEvent.Version, Source = "/" + (intent.ServiceId.ServiceName ?? ""), EventID = intent.Id.ToString(), EventTime = DateTimeOffset.Now, ContentType = "application/json", Data = CloudEventsSerialization.Serialize(eventData) }; var content = CloudEventsSerialization.Serialize(eventEnvelope); foreach (var eventsDirectory in ReadEventObservers()) { var fileName = intent.Id.ToString() + ".json"; var filePath = Path.Combine(eventsDirectory, fileName); try { File.WriteAllText(filePath, content, Encoding.UTF8); } catch (IOException) { } } return(Task.FromResult(0)); }
public Task <ActiveRoutineInfo> ScheduleContinuationAsync( ContinueRoutineIntent intent, CancellationToken ct) { var eventData = new RoutineEventData { ServiceId = intent.Continuation.ServiceId, Routine = intent.Continuation.Routine, Callee = intent.Callee, Result = _serializer.SerializeToString(intent.Result) }; var eventEnvelope = new RoutineEventEnvelope { CloudEventsVersion = CloudEventsEnvelope.Version, EventType = DasyncCloudEventsTypes.ContinueRoutine.Name, EventTypeVersion = DasyncCloudEventsTypes.ContinueRoutine.Version, Source = "/" + (intent.Callee?.ServiceId.ServiceName ?? ""), EventID = intent.Id.ToString(), EventTime = DateTimeOffset.Now, EventDeliveryTime = intent.Continuation.ContinueAt?.ToUniversalTime(), ETag = intent.Continuation.Routine.ETag, ContentType = "application/json", Data = CloudEventsSerialization.Serialize(eventData) }; var fileName = intent.Id.ToString() + ".json"; var filePath = Path.Combine(_transitionsDirectory, fileName); var content = CloudEventsSerialization.Serialize(eventEnvelope); File.WriteAllText(filePath, content, Encoding.UTF8); var info = new ActiveRoutineInfo { RoutineId = intent.Continuation.Routine.RoutineId }; return(Task.FromResult(info)); }
public TransitionCarrier(FileBasedFabric fabric, RoutineEventEnvelope eventEnvelope) { _fabric = fabric; _eventEnvelope = eventEnvelope; }