This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
author submissions: initial implementation
- Loading branch information
Showing
15 changed files
with
241 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,34 @@ | ||
import requests | ||
from os import environ | ||
|
||
import requests | ||
from django.http import JsonResponse | ||
from requests.exceptions import HTTPError, RequestException | ||
from requests.exceptions import RequestException | ||
from rest_framework import status | ||
|
||
AIRFLOW_BASE_URL = environ.get("AIRFLOW_BASE_URL") | ||
|
||
AIRFLOW_HEADERS = {"Content-Type": "application/json", "Authorization": f"Basic {environ.get('AIRFLOW_TOKEN')}"} | ||
|
||
AIRFLOW_BASE_URL = environ.get('AIRFLOW_BASE_URL') | ||
|
||
AIRFLOW_HEADERS = { | ||
"Content-Type": "application/json", | ||
"Authorization": f"Basic {environ.get('AIRFLOW_TOKEN')}" | ||
} | ||
def trigger_airflow_dag(dag_id, workflow_id, extra_data=None): | ||
"""Triggers an airflow dag. | ||
def trigger_airflow_dag(dag_id,workflow_id, extra_data = None): | ||
""" triggers an airflow dag | ||
:param dag_id: name of the dag to run | ||
:param workflow_id: id of the workflow being triggered | ||
:return request response""" | ||
:returns: request response | ||
""" | ||
|
||
data = { | ||
"dag_run_id": workflow_id, | ||
"conf": | ||
{ | ||
"workflow_id": workflow_id | ||
} | ||
} | ||
data = {"dag_run_id": workflow_id, "conf": {"workflow_id": workflow_id}} | ||
|
||
if extra_data is not None: | ||
data["conf"].update(extra_data) | ||
|
||
url = f'{AIRFLOW_BASE_URL}/api/v1/dags/{dag_id}/dagRuns' | ||
url = f"{AIRFLOW_BASE_URL}/api/v1/dags/{dag_id}/dagRuns" | ||
|
||
try: | ||
response = requests.post(url, json=data, headers=AIRFLOW_HEADERS, timeout=300) | ||
response = requests.post(url, json=data, headers=AIRFLOW_HEADERS) | ||
response.raise_for_status() | ||
return JsonResponse(response.json()) | ||
except HTTPError as http_err: | ||
return JsonResponse({'error': f'HTTP error occurred: {http_err}'}, status=response.status_code) | ||
except RequestException as req_err: | ||
return JsonResponse({'error': f'Request error occurred: {req_err}'}, status=500) | ||
data = {"error": req_err} | ||
return JsonResponse(data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
backoffice/workflows/migrations/0007_alter_workflow_core_alter_workflow_is_update.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 4.2.6 on 2024-06-20 09:07 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("workflows", "0006_workflow__created_at_workflow__updated_at"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="workflow", | ||
name="core", | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AlterField( | ||
model_name="workflow", | ||
name="is_update", | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
40 changes: 40 additions & 0 deletions
40
backoffice/workflows/migrations/0008_alter_workflow_status_alter_workflow_workflow_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 4.2.6 on 2024-07-09 12:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("workflows", "0007_alter_workflow_core_alter_workflow_is_update"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="workflow", | ||
name="status", | ||
field=models.CharField( | ||
choices=[ | ||
("running", "Running"), | ||
("approval", "Waiting for approva"), | ||
("completed", "Completed"), | ||
("error", "Error"), | ||
], | ||
default="running", | ||
max_length=30, | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="workflow", | ||
name="workflow_type", | ||
field=models.CharField( | ||
choices=[ | ||
("HEP_CREATE", "HEP create"), | ||
("HEP_UPDATE", "HEP update"), | ||
("AUTHOR_CREATE", "Author create"), | ||
("AUTHOR_UPDATE", "Author update"), | ||
], | ||
default="HEP_CREATE", | ||
max_length=30, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.