1+ from airflow .decorators import dag , task
2+ from airflow .models import Param
3+
4+ from dags import DEFAULT_DAG_ARGUMENTS
5+ from dags .dags_utils import push_dag_downstream , get_dag_param
6+ from dags .notice_processing_pipeline import NOTICE_NORMALISATION_PIPELINE_TASK_ID
7+ from dags .operators .DagBatchPipelineOperator import NOTICE_IDS_KEY , TriggerNoticeBatchPipelineOperator
8+ from dags .pipelines .notice_selectors_pipelines import notice_ids_selector_by_status
9+ from ted_sws .core .model .notice import NoticeStatus
10+ from ted_sws .event_manager .adapters .event_log_decorator import event_log
11+ from ted_sws .event_manager .model .event_message import TechnicalEventMessage , EventMessageMetadata , EventMessageProcessType
12+
13+ DAG_ID = "reprocess_notices_from_backlog_by_status"
14+ DAG_NAME = "Reprocess notices from backlog by status"
15+
16+ TRIGGER_NOTICE_PROCESS_WORKFLOW_TASK_ID = "trigger_notice_process_workflow"
17+ START_DATE_DAG_PARAM = "start_date"
18+ END_DATE_DAG_PARAM = "end_date"
19+ NOTICE_STATUSES_DAG_PARAM = "notice_statuses"
20+
21+
22+ @dag (
23+ default_args = DEFAULT_DAG_ARGUMENTS ,
24+ dag_id = DAG_ID ,
25+ dag_display_name = DAG_NAME ,
26+ schedule_interval = None ,
27+ tags = ['selector' , 're-transform' ],
28+ params = {
29+
30+ NOTICE_STATUSES_DAG_PARAM : Param (
31+ default = [],
32+ type = "array" ,
33+ title = "Notice Statuses" ,
34+ description = "Required. Select one or more notice statuses to reprocess." ,
35+ examples = [status .name for status in NoticeStatus ]
36+ ),
37+ START_DATE_DAG_PARAM : Param (default = "" , type = ["null" , "string" ], format = "date" , description = "Start publication date (YYYY-MM-DD)" ),
38+ END_DATE_DAG_PARAM : Param (default = "" , type = ["null" , "string" ], format = "date" , description = "End publication date (YYYY-MM-DD)" )
39+ }
40+ )
41+ def reprocess_notices_from_backlog_by_status ():
42+ @task
43+ @event_log (TechnicalEventMessage (
44+ message = "select_notices_for_re_transform" ,
45+ metadata = EventMessageMetadata (
46+ process_type = EventMessageProcessType .DAG ,
47+ process_name = DAG_ID
48+ ))
49+ )
50+ def select_notices_for_re_transform ():
51+ start_date = get_dag_param (key = START_DATE_DAG_PARAM , default_value = "" )
52+ end_date = get_dag_param (key = END_DATE_DAG_PARAM ,default_value = "" )
53+ statuses_param = get_dag_param (key = NOTICE_STATUSES_DAG_PARAM )
54+
55+ notice_statuses = [NoticeStatus [status_str ] for status_str in statuses_param ]
56+
57+ notice_ids = notice_ids_selector_by_status (
58+ notice_statuses = notice_statuses ,
59+ start_date = start_date ,
60+ end_date = end_date
61+ )
62+
63+ push_dag_downstream (key = NOTICE_IDS_KEY , value = notice_ids )
64+
65+ trigger_notice_process_workflow = TriggerNoticeBatchPipelineOperator (
66+ task_id = TRIGGER_NOTICE_PROCESS_WORKFLOW_TASK_ID ,
67+ start_with_step_name = NOTICE_NORMALISATION_PIPELINE_TASK_ID
68+ )
69+
70+ select_notices_for_re_transform () >> trigger_notice_process_workflow
71+
72+ dag = reprocess_notices_from_backlog_by_status ()
0 commit comments