Пример #1
0
        private CompletedWorkbookInfo CompleteWorkbook(PackagedWorkbookTemplateInfo templateInfo, bool hasAnyData)
        {
            var workbookNameToUse = hasAnyData
                ? $"{templateInfo.Name}{_config.CustomWorkbookSuffix}"
                : $"{templateInfo.Name}{_config.CustomWorkbookSuffix} [No Data]";

            try
            {
                // Copy the template to where we want the workbook to live
                var finalWorkbookPath = Path.Combine(_workbooksOutputDir, $"{workbookNameToUse}.twbx");

                // In the case of custom workbooks, we don't have a custom folder in our output. Create one if we need to
                Directory.CreateDirectory(Path.GetDirectoryName(finalWorkbookPath));

                File.Copy(templateInfo.Path, finalWorkbookPath);

                // Replace necessary hyper files in the workbook
                ProcessPackagedWorkbook(finalWorkbookPath);
                _logger.LogDebug("Workbook {completedWorkbookName} complete", templateInfo.Name);
                return(new CompletedWorkbookInfo(templateInfo, workbookNameToUse, finalWorkbookPath, hasAnyData));
            }
            catch (Exception ex)
            {
                var message = $"Exception occurred while generating workbook {templateInfo.Name}. Exception: {ex.Message}";
                _logger.LogError(message);
                return(CompletedWorkbookInfo.GetFailedInfo(templateInfo, new WorkbookGeneratingException(message, ex)));
            }
        }
Пример #2
0
        private async Task <WorkbookPublishResult> PublishWorkbook(string projectId, CompletedWorkbookInfo completedWorkbookInfo, TableauServerRestApi restApi, IList <string> tags)
        {
            if (!completedWorkbookInfo.GeneratedSuccessfully)
            {
                return(new WorkbookPublishResult(
                           completedWorkbookInfo.OriginalWorkbookName,
                           new WorkbookPublishingException($"Workbook {completedWorkbookInfo.OriginalWorkbookName} was not generated successfully. Skipping publishing", completedWorkbookInfo.Exception)));
            }

            var publishWorkbookRequest = new PublishWorkbookRequest(
                completedWorkbookInfo.WorkbookPath,
                projectId,
                completedWorkbookInfo.FinalWorkbookName,
                overwriteExistingWorkbook: true)
            {
                Credentials = _dbCreds,
            };

            WorkbookInfo workbookInfo;

            try
            {
                workbookInfo = await Retry.DoWithRetries <RestApiException, WorkbookInfo>(
                    nameof(WorkbookPublisher),
                    _logger,
                    async() => await restApi.PublishWorkbook(publishWorkbookRequest));

                _logger.LogDebug("Workbook `{publishedWorkbookName}` was published to Tableau Server as ID `{newWorkbookId}`", publishWorkbookRequest.WorkbookNameOnTableauServer, workbookInfo.Id);
            }
            catch (RestApiException ex)
            {
                var errorMessage = $"Failed to publish workbook `{completedWorkbookInfo.WorkbookPath}` after multiple retries. Exception was: {ex.Message}";
                _logger.LogError(errorMessage);
                return(new WorkbookPublishResult(completedWorkbookInfo.OriginalWorkbookName, new WorkbookPublishingException(errorMessage)));
            }

            if (_publisherSettings.ApplyPluginProvidedTagsToWorkbooks && tags != null && tags.Count > 0)
            {
                await AddTagsToWorkbook(workbookInfo, tags, restApi);
            }

            return(new WorkbookPublishResult(workbookInfo.Name));
        }
Пример #3
0
        private async Task <WorkbookPublishResult> PublishWorkbook(string projectId, CompletedWorkbookInfo completedWorkbookInfo, TableauServerRestApi restApi, IList <string> tags)
        {
            if (!completedWorkbookInfo.GeneratedSuccessfully)
            {
                return(WorkbookPublishResult.Fail(
                           completedWorkbookInfo.OriginalWorkbookName,
                           new WorkbookPublishingException($"Workbook {completedWorkbookInfo.OriginalWorkbookName} was not generated successfully. Skipping publishing", completedWorkbookInfo.Exception)));
            }

            var publishWorkbookRequest = new PublishWorkbookRequest(
                completedWorkbookInfo.WorkbookPath,
                projectId,
                completedWorkbookInfo.FinalWorkbookName,
                overwriteExistingWorkbook: true)
            {
                Credentials = _dbCreds,
            };

            WorkbookPublishResult workbookPublishResult;

            try
            {
                var retryOnExceptionPolicy = Policy
                                             .Handle <RestApiException>()
                                             .WaitAndRetryAsync(
                    new []
                {
                    TimeSpan.FromSeconds(30),
                    TimeSpan.FromSeconds(60),
                },
                    (exception, timeSpan, retryCount, context) =>
                {
                    _logger.LogDebug("Got an exception trying to publish workbook `{failedWorkbookName}`. This is retry number {retryCount}. Exception was: `{exceptionMessage}`", completedWorkbookInfo.FinalWorkbookName ?? "null", retryCount, exception?.Message ?? "null");
                });

                var handleExceptionPolicy = Policy <WorkbookPublishResult>
                                            .Handle <RestApiException>(ex => ex.IsTimeoutException)
                                            .FallbackAsync(WorkbookPublishResult.Timeout(completedWorkbookInfo.FinalWorkbookName));

                workbookPublishResult = await retryOnExceptionPolicy
                                        .WrapAsync(handleExceptionPolicy)
                                        .ExecuteAsync(async() =>
                {
                    var workbookInfo = await restApi.PublishWorkbook(publishWorkbookRequest);
                    return(WorkbookPublishResult.Success(completedWorkbookInfo.FinalWorkbookName, workbookInfo));
                });
            }
            catch (RestApiException ex)
            {
                var errorMessage = $"Failed to publish workbook `{completedWorkbookInfo.WorkbookPath}` after multiple retries. Exception was: {ex.Message}";
                _logger.LogError(errorMessage);
                return(WorkbookPublishResult.Fail(completedWorkbookInfo.OriginalWorkbookName, new WorkbookPublishingException(errorMessage)));
            }

            if (workbookPublishResult.PublishState == WorkbookPublishResult.WorkbookPublishState.Success &&
                _publisherSettings.ApplyPluginProvidedTagsToWorkbooks &&
                tags != null &&
                tags.Count > 0)
            {
                await AddTagsToWorkbook(workbookPublishResult, tags, restApi);
            }

            if (workbookPublishResult.PublishState == WorkbookPublishResult.WorkbookPublishState.Success)
            {
                _logger.LogDebug("Workbook `{publishedWorkbookName}` was published to Tableau Server as ID `{newWorkbookId}`", publishWorkbookRequest.WorkbookNameOnTableauServer, workbookPublishResult.PublishedWorkbookId);
            }
            else
            {
                _logger.LogDebug("Publishing attempt for workbook `{originalWorkbookName}` returned non-successful publishing status. Status: {publishingStatus}", publishWorkbookRequest.WorkbookNameOnTableauServer, workbookPublishResult.PublishState.ToString());
            }

            return(workbookPublishResult);
        }