Tableau Migration SDK 5.1.1
  • Articles
  • Code Samples
  • Python API Reference
  • C# API Reference
Show / Hide Table of Contents
  • Filters
    • Filter projects by name
    • Filter users by SiteRole
    • Filter Custom Views by 'Shared' flag
  • Mappings
    • Username email
    • Rename projects
    • Change projects
  • Transformers
    • Add tags to content
    • Encrypt Extracts
    • Adjust 'Start At' to Scheduled Tasks
    • Change default users for Custom Views
    • Action URL XML Transformer
  • Post-Publish Hooks
    • Update permissions
  • Bulk Post-Publish Hooks
    • Bulk logging
  • Batch Migration Completed Hooks
    • Batch migration logging
  • Migration Action Completed Hooks
    • Migration action logging

Sample: Migration Action Logging

This sample illustrates how to implement migration action logging, capturing the statuses of migration actions upon completion.

  • Python
  • C#

Migration Action Completed Hook Class

To log migration action statuses in Python, you can utilize the following hook class:

import logging
from tableau_migration import(
    MigrationActionCompletedHookBase,
    IMigrationActionResult
    )


class LogMigrationActionsHook(MigrationActionCompletedHookBase):
    def __init__(self) -> None:
        super().__init__()
        
        # Create a logger for this class
        self._logger = logging.getLogger(__name__)
        
    def execute(self, ctx: IMigrationActionResult) -> IMigrationActionResult:
        if(ctx.success):
            self._logger.info("Migration action completed successfully.")
        else:
            all_errors = "\n".join(ctx.errors)
            self._logger.warning("Migration action completed with errors:\n%s", all_errors)
            
        return None

Registration

plan_builder.hooks.add(LogMigrationActionsHookForUsers)
plan_builder.hooks.add(LogMigrationActionsHookForGroups)

See hook registration for more details.

Migration Action Completed Hook Class

In C#, you can implement the migration action completed hook as demonstrated below:

public class LogMigrationActionsHook : IMigrationActionCompletedHook
{
    private readonly ILogger<LogMigrationActionsHook> _logger;

    public LogMigrationActionsHook(ILogger<LogMigrationActionsHook> logger)
    {
        _logger = logger;
    }

    public Task<IMigrationActionResult?> ExecuteAsync(IMigrationActionResult ctx, CancellationToken cancel)
    {
        if (ctx.Success)
        {
            _logger.LogInformation("Migration action completed successfully.");
        }
        else
        {
            _logger.LogWarning(
                "Migration action completed with errors:{NewLine}{Errors}",
                Environment.NewLine,
                String.Join(Environment.NewLine, ctx.Errors.Select(e => e.ToString())));
        }

        return Task.FromResult<IMigrationActionResult?>(ctx);
    }
}

Registration

To register the hook in C#, follow the instructions provided in the documentation.

_planBuilder.Hooks.Add<LogMigrationActionsHook>();

Dependency Injection

Learn more about dependency injection here.

services.AddScoped<LogMigrationActionsHook>();
  • Edit this page
In this article