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.
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.
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<>));