public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "post", Route = "unsubscribe/{teamId}")] HttpRequest req,
            [DurableClient] IDurableOrchestrationClient starter,
            string teamId,
            ILogger log)
        {
            try
            {
                var connection = await _scheduleConnectorService.GetConnectionAsync(teamId).ConfigureAwait(false);
            }
            catch (KeyNotFoundException)
            {
                return(new NotFoundResult());
            }

            // ensure that in the very brief period of time before the connection is deleted that
            // the orchestrators are not started
            await _scheduleConnectorService.UpdateEnabledAsync(teamId, false).ConfigureAwait(false);

            // and that any running instances are terminated
            await StopTrigger.StopRunningOrchestratorsAsync(teamId, starter).ConfigureAwait(false);

            // finally, delete the connection
            await _scheduleConnectorService.DeleteConnectionAsync(teamId).ConfigureAwait(false);

            log.LogUnsubscribeTeam(teamId);

            return(new OkResult());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "post", Route = "unsubscribe/{teamId}")] HttpRequest req,
            [OrchestrationClient] DurableOrchestrationClient starter,
            string teamId,
            ILogger log)
        {
            try
            {
                var connection = await _scheduleConnectorService.GetConnectionAsync(teamId);
            }
            catch (KeyNotFoundException)
            {
                return(new NotFoundResult());
            }

            var tasks = new Task[]
            {
                starter.TerminateAsync(teamId, nameof(UnsubscribeTrigger)),
                _secretsService.DeleteCredentialsAsync(teamId),
                _secretsService.DeleteTokenAsync(teamId),
                _scheduleConnectorService.DeleteConnectionAsync(teamId)
            };

            await Task.WhenAll(tasks);

            return(new OkResult());
        }