public async Task CommitAsync(ScheduledActions actions, ITransitionCarrier transitionCarrier, TransitionCommitOptions options, CancellationToken ct) { if (actions.ExecuteRoutineIntents?.Count > 0) { foreach (var intent in actions.ExecuteRoutineIntents) { var serviceDefinition = GetServiceDefinition(intent.ServiceId); if (serviceDefinition.Type == ServiceType.Local) { #pragma warning disable CS4014 Task.Run(() => RunRoutineInBackground(serviceDefinition, intent)); #pragma warning restore CS4014 } else { var platformHttpClient = _platformHttpClientProvider.GetClient(serviceDefinition); var routineInfo = await platformHttpClient.ScheduleRoutineAsync(intent, _transitionUserContext.Current, ct); if (routineInfo.Result != null) { _routineCompletionSink.OnRoutineCompleted(intent.Id, routineInfo.Result); } } } } if (actions.RaiseEventIntents?.Count > 0) { foreach (var intent in actions.RaiseEventIntents) { await _eventDispatcher.PublishEvent(intent); } } }
private async void SubscribePeriodicallyInBackground( EventDescriptor eventDesc, ServiceId subscriber, IServiceDefinition publisherServiceDefinition) { var subscriberServiceDefinition = GetServiceDefinition(subscriber); while (true) { var client = _platformHttpClientProvider.GetClient(publisherServiceDefinition); try { await client.SubscribeToEvent(eventDesc, subscriber, publisherServiceDefinition); await Task.Delay(TimeSpan.FromMinutes(2)); } catch { await Task.Delay(TimeSpan.FromSeconds(5)); } } }