<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Trigger Databricks Workflow when other workflows succeeded in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/trigger-databricks-workflow-when-other-workflows-succeeded/m-p/109741#M43377</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have 3 separate workflows with 3 different triggers and the thing I would like to achieve is - after all of these 3 jobs completed &amp;amp; succeeded I would like to trigger another job. Is it possible?&lt;/P&gt;&lt;P&gt;These 3 jobs have to stay separate (I cannot combine them into a single pipeline and add a dependent task to them).&lt;/P&gt;</description>
    <pubDate>Tue, 11 Feb 2025 09:21:49 GMT</pubDate>
    <dc:creator>dbuserng</dc:creator>
    <dc:date>2025-02-11T09:21:49Z</dc:date>
    <item>
      <title>Trigger Databricks Workflow when other workflows succeeded</title>
      <link>https://community.databricks.com/t5/data-engineering/trigger-databricks-workflow-when-other-workflows-succeeded/m-p/109741#M43377</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have 3 separate workflows with 3 different triggers and the thing I would like to achieve is - after all of these 3 jobs completed &amp;amp; succeeded I would like to trigger another job. Is it possible?&lt;/P&gt;&lt;P&gt;These 3 jobs have to stay separate (I cannot combine them into a single pipeline and add a dependent task to them).&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2025 09:21:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/trigger-databricks-workflow-when-other-workflows-succeeded/m-p/109741#M43377</guid>
      <dc:creator>dbuserng</dc:creator>
      <dc:date>2025-02-11T09:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger Databricks Workflow when other workflows succeeded</title>
      <link>https://community.databricks.com/t5/data-engineering/trigger-databricks-workflow-when-other-workflows-succeeded/m-p/109779#M43391</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/144942"&gt;@dbuserng&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;It is possible but it requires custom code setup based on your use-case. You can use job REST API: &lt;A href="https://docs.databricks.com/api/workspace/jobs" target="_blank"&gt;https://docs.databricks.com/api/workspace/jobs&lt;/A&gt;.&lt;/P&gt;
&lt;P class="p1"&gt;&lt;STRONG&gt;Create a Monitoring Job&lt;/STRONG&gt;: Set up a job that will monitor the completion status of the three workflows. This job will periodically check if all three workflows have completed successfully.&lt;/P&gt;
&lt;P class="p1"&gt;&lt;STRONG&gt;Use the Jobs API&lt;/STRONG&gt;: Utilize the Databricks Jobs API to check the status of the workflows. You can use the jobs/runs/list endpoint to get the status of the runs for each workflow.&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;STRONG&gt;Conditional Trigger&lt;/STRONG&gt;: In the monitoring job, implement logic to check if all three workflows have completed successfully. If they have, trigger the desired job.&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;Here is a high-level example of how you can implement this:&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;import requests&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;# Define the job IDs for the three workflows&lt;/P&gt;
&lt;P class="p1"&gt;workflow_ids = [workflow1_id, workflow2_id, workflow3_id]&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;# Function to check the status of a workflow&lt;/P&gt;
&lt;P class="p1"&gt;def check_workflow_status(job_id):&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;response = requests.get(f'https://&amp;lt;databricks-instance&amp;gt;/api/2.0/jobs/runs/list?job_id={job_id}')&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;runs = response.json().get('runs', [])&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;if runs and runs[0]['state']['life_cycle_state'] == 'TERMINATED' and runs[0]['state']['result_state'] == 'SUCCESS':&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;return True&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;return False&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;# Check the status of all workflows&lt;/P&gt;
&lt;P class="p1"&gt;all_completed = all(check_workflow_status(job_id) for job_id in workflow_ids)&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;# If all workflows are completed successfully, trigger the next job&lt;/P&gt;
&lt;P class="p1"&gt;if all_completed:&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;trigger_response = requests.post('https://&amp;lt;databricks-instance&amp;gt;/api/2.0/jobs/run-now', json={"job_id": next_job_id})&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;if trigger_response.status_code == 200:&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;print("Next job triggered successfully")&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;else:&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;print("Failed to trigger the next job")&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2025 12:53:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/trigger-databricks-workflow-when-other-workflows-succeeded/m-p/109779#M43391</guid>
      <dc:creator>Alberto_Umana</dc:creator>
      <dc:date>2025-02-11T12:53:24Z</dc:date>
    </item>
  </channel>
</rss>

