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: Adjust 'Start At' to Scheduled Tasks

This sample demonstrates how to adjust the 'Start At' of a Scheduled Task.

Both the Python and C# transformer classes inherit from a base class responsible for the core functionality.

  • Python
  • C#

Transformer Class

To adjust the 'Start At' in Python, you can use the following transformer class:

from datetime import time
from tableau_migration import (
    ContentTransformerBase,
    ICloudExtractRefreshTask
)

class SimpleScheduleStartAtTransformer(ContentTransformerBase[ICloudExtractRefreshTask]):
    def transform(self, itemToTransform: ICloudExtractRefreshTask) -> ICloudExtractRefreshTask:
        # In this example, the `Start At` time is in the UTC time zone.
        if itemToTransform.schedule.frequency_details.start_at:
            prev_start_at = itemToTransform.schedule.frequency_details.start_at
            # A simple conversion to the EDT time zone.
            itemToTransform.schedule.frequency_details.start_at = time(prev_start_at.hour - 4, prev_start_at.minute, prev_start_at.second, prev_start_at.microsecond);
        
        return itemToTransform

Registration

plan_builder.transformers.add(SimpleScheduleStartAtTransformer)

See hook registration for more details.

Transformer Class

In C#, the transformer class for adjusting the 'Start At' of a given Scheduled Task is implemented as follows:

public class SimpleScheduleStartAtTransformer<T> 
    : ContentTransformerBase<T> 
    where T : IWithSchedule<ICloudSchedule>
{
    private readonly ILogger<IContentTransformer<T>>? _logger;

    public SimpleScheduleStartAtTransformer(
        ISharedResourcesLocalizer localizer, 
        ILogger<IContentTransformer<T>> logger) 
        : base(
              localizer, 
              logger)
    {
        _logger = logger;
    }

    public override async Task<T?> TransformAsync(
        T itemToTransform, 
        CancellationToken cancel)
    {
        // In this example, the `Start At` time is in the UTC time zone.
        if (itemToTransform.Schedule.FrequencyDetails.StartAt is not null)
        {
            // A simple conversion to the EDT time zone.
            var updatedStartAt = itemToTransform.Schedule.FrequencyDetails.StartAt.Value.AddHours(-4);

            _logger?.LogInformation(
                @"Adjusting the 'Start At' from {previousStartAt} to {updatedStartAt}.",
                itemToTransform.Schedule.FrequencyDetails.StartAt.Value,
                updatedStartAt);

            itemToTransform.Schedule.FrequencyDetails.StartAt = updatedStartAt;
        }

        return await Task.FromResult(itemToTransform);
    }
}

Registration

To register the transformer in C#, follow the guidance provided in the documentation.

_planBuilder.Transformers.Add<SimpleScheduleStartAtTransformer<ICloudExtractRefreshTask>, ICloudExtractRefreshTask>();

Dependency Injection

Learn more about dependency injection here.

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