How to update ADF schedule triggers dynamically

Gmkreddy 0 Reputation points
2023-04-30T03:32:56.0666667+00:00

For a pipeline there are many schedule triggers.

How to modify these triggers start time dynamically?

the start time is updated by business team in sql server in one of the table and that start time should update in triggers dynamically.

Could anyone please suggest how to design this.

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,373 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Sedat SALMAN 14,180 Reputation points MVP
    2023-05-01T07:45:36.9433333+00:00

    You can programmatically update the start time of your ADF schedule triggers using the Azure Data Factory REST API.

    • Using the ADF REST API, create a web service that reads the start time from the SQL Server table and updates the schedule trigger.
    • Using a timer trigger in Azure Functions or Logic Apps, call the web service on a regular basis (for example, every minute). This ensures that the schedule trigger is dynamically updated based on the SQL Server table values.
    • Set up your ADF pipeline to use the new schedule trigger. This can be accomplished by either adding a new trigger or updating an existing trigger in your pipeline definition.

    You can modify the following code block according to your requirements

    
    // Construct the REST API URL for the schedule trigger
    string triggerUrl = $"https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/triggers/{triggerName}?api-version=2018-06-01";
    
    DateTime newStartTime = ReadNewStartTimeFromSqlTable();
    
    string payload = $"{{ 'properties': {{ 'startTime': '{newStartTime.ToString("s")}' }} }}";
    
    HttpClient client = new HttpClient();
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
    HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");
    HttpResponseMessage response = await client.PatchAsync(triggerUrl, content);
    
    if (response.IsSuccessStatusCode)
    {
        Console.WriteLine("trigger updated");
    }
    else
    {
        string errorResponse = await response.Content.ReadAsStringAsync();
        Console.WriteLine(errorResponse);
    }
    
    
    0 comments No comments

  2. AnnuKumari-MSFT 34,556 Reputation points Microsoft Employee Moderator
    2023-05-02T09:34:10.1333333+00:00

    Hi Gmkreddy ,

    Welcome to Microsoft Q&A platform and thanks for posting your question here.

    I understand you are trying to update the ADF pipeline schedule trigger start time dynamically. Please let me know if that is not the ask here.

    You can try sending REST API request to do so. Here is the REST API to update the trigger:

    PUT https://management.azure.com/subscriptions/<subscriptionID>/resourceGroups/<ResourceGroupName>/providers/Microsoft.DataFactory/factories/<exampleFactoryName>/triggers/<exampleTrigger>?api-version=2018-06-01 
    
    

    Provide the start date value dynamically in the request body via pipeline parameter instead of hardcoding it.

    For more details, Check this document: Triggers_Update

    Hope it helps. Kindly accept the answer if it's helpful. Thankyou


  3. Rajesh Gopisetti 5 Reputation points
    2023-08-07T17:58:29.2+00:00

    How can we start the updated scheduled trigger??? Once it updates it is still in stop status

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.