public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (!(_html is IViewContextAware htmlHelper)) { throw new Exception("Uncontextualizable IHtmlHelper."); } htmlHelper.Contextualize(ViewContext); var viewModel = new VercelLatestDeploymentViewModel { InitializationStatus = _deploymentService.GetInitializationStatus(), }; if ( viewModel.InitializationStatus.IsReadConfigured ) { try { viewModel.LatestDeployment = await _deploymentService.GetLatestProductionDeploymentAsync(); viewModel.IsWaitingForDeployment = _deploymentStatusService.IsWaitingForDeployment(); } catch (Exception e) { _logger.LogWarning(e, "Couldn't get latest production deployment."); } } var renderedHtml = await _html.PartialAsync("VercelLatestDeployment", viewModel); output.TagName = null; output.Content.SetHtmlContent(renderedHtml); }
public virtual Task <Deployment> GetLatestProductionDeploymentAsync() { return(_cache.GetOrAddAsync(DeploymentCacheKeys.LatestDeployment, async entry => { ThrowIfReadNotConfigured(); entry.AddExpirationToken(_signal.GetToken(DeploymentCacheKeys.LatestDeployment)); var latestDeployment = await GetLatestProductionDeploymentAsync_Impl(); // Reset waiting for deployment, if another new production deployment has arrived _deploymentStatus.MaybeResetWaitingForDeployment(latestDeployment?.Id); entry.SetAbsoluteExpiration(DateTime.UtcNow + TimeSpan.FromSeconds( _deploymentStatus.IsWaitingForDeployment() ? _deploymentOptions.HighPriorityCacheInSeconds : _deploymentOptions.CacheInSeconds )); return latestDeployment; })); }