4
4
import time
5
5
from datetime import datetime , timedelta
6
6
from astropy .time import Time
7
+ import pytz
7
8
from airflow import DAG
8
9
from airflow .sensors .filesystem import FileSensor
9
10
from airflow .operators .bash import BashOperator
@@ -74,7 +75,7 @@ def poke(self, context) -> bool:
74
75
catchup = False ,
75
76
on_failure_callback = [
76
77
send_slack_notification_partial (
77
- text = "ApogeeReduction-airflow DAG failed on {{ (ds | string | to_datetime - timedelta(days=1)).strftime('%Y-%m-%d ') }}" ,
78
+ text = "ApogeeReduction-airflow DAG failed on {{ task_instance.xcom_pull(task_ids='setup.date_mjd ') }}" ,
78
79
)
79
80
]
80
81
) as dag :
@@ -98,7 +99,7 @@ def poke(self, context) -> bool:
98
99
bash_command = (
99
100
"ORIG_PWD=$(pwd)\n "
100
101
"cd /mnt/ceph/users/sdssv/raw/APOGEE/sdsscore/\n "
101
- "./update.sh\n "
102
+ # "./update.sh\n"
102
103
"cd $ORIG_PWD"
103
104
)
104
105
)
@@ -108,7 +109,12 @@ def poke(self, context) -> bool:
108
109
with TaskGroup (group_id = "setup" ) as group_setup :
109
110
mjd = PythonOperator (
110
111
task_id = "mjd" ,
111
- python_callable = lambda data_interval_start , ** _ : int (Time (data_interval_start ).mjd ) - 1 # +1 offset to get the most recent day
112
+ python_callable = lambda data_interval_start , ** _ : int (Time (data_interval_start ).mjd ) - 2
113
+ )
114
+
115
+ date_mjd = PythonOperator (
116
+ task_id = "date_mjd" ,
117
+ python_callable = lambda data_interval_start , ** _ : (data_interval_start .astimezone (pytz .timezone ('America/New_York' )) - timedelta (days = 2 )).strftime ('%Y-%m-%d' )
112
118
)
113
119
114
120
observatory_groups = []
@@ -119,7 +125,7 @@ def poke(self, context) -> bool:
119
125
python_callable = lambda ** _ : None , # Simple no-op function
120
126
on_success_callback = [
121
127
send_slack_notification_partial (
122
- text = "Starting reduction for " + observatory + " for SJD {{ task_instance.xcom_pull(task_ids='setup.mjd') }} (night of {{ (ds | string | to_datetime - timedelta(days=1)).strftime('%Y-%m-%d ') }}). Exposure list can be found at https://users.flatironinstitute.org/~asaydjari/" + slack_token + "/gitcode/ApogeeReduction.jl/metadata/observing_log_viewer/?sjd={{ task_instance.xcom_pull(task_ids='setup.mjd') }}&site=" + observatory
128
+ text = "Starting reduction for " + observatory + " for SJD {{ task_instance.xcom_pull(task_ids='setup.mjd') }} (night of {{ task_instance.xcom_pull(task_ids='setup.date_mjd ') }}). Exposure list can be found at https://users.flatironinstitute.org/~asaydjari/" + slack_token + "/gitcode/ApogeeReduction.jl/metadata/observing_log_viewer/?sjd={{ task_instance.xcom_pull(task_ids='setup.mjd') }}&site=" + observatory
123
129
)
124
130
]
125
131
)
@@ -130,16 +136,16 @@ def poke(self, context) -> bool:
130
136
task_id = "science" ,
131
137
python_callable = submit_and_wait ,
132
138
op_kwargs = {
133
- 'bash_command' : f"{ sbatch_prefix } --job-name=ar_all_{ observatory } _{{{{ ti.xcom_pull(task_ids='setup.mjd') }}}} /mnt/home/sdssv/gitcode/ApogeeReduction.jl/scripts/daily/run_all.sh { observatory } {{{{ ti.xcom_pull(task_ids='setup.mjd') }}}} { OUT_DIR } /mnt/home/sdssv/gitcode/arMADGICS.jl false"
139
+ 'bash_command' : f"{ sbatch_prefix } --job-name=ar_all_{ observatory } _{{{{ ti.xcom_pull(task_ids='setup.mjd') }}}} /mnt/home/sdssv/gitcode/ApogeeReduction.jl/scripts/daily/run_all.sh { observatory } {{{{ ti.xcom_pull(task_ids='setup.mjd') }}}} { OUT_DIR } /mnt/home/sdssv/gitcode/arMADGICS.jl/ false"
134
140
},
135
141
on_success_callback = [
136
142
send_slack_notification_partial (
137
- text = observatory + " science frames reduced for SJD {{ ti.xcom_pull(task_ids='setup.mjd') }} (night of {{ (ds | string | to_datetime - timedelta(days=1)).strftime('%Y-%m-%d ') }})." ,
143
+ text = observatory + " science frames reduced for SJD {{ ti.xcom_pull(task_ids='setup.mjd') }} (night of {{ task_instance.xcom_pull(task_ids='setup.date_mjd ') }})." ,
138
144
)
139
145
],
140
146
on_failure_callback = [
141
147
send_slack_notification_partial (
142
- text = observatory + " science frame reduction failed for SJD {{ ti.xcom_pull(task_ids='setup.mjd') }} (night of {{ (ds | string | to_datetime - timedelta(days=1)).strftime('%Y-%m-%d ') }}). :picard_facepalm:" ,
148
+ text = observatory + " science frame reduction failed for SJD {{ ti.xcom_pull(task_ids='setup.mjd') }} (night of {{ task_instance.xcom_pull(task_ids='setup.date_mjd ') }}). :picard_facepalm:" ,
143
149
)
144
150
]
145
151
)
@@ -153,7 +159,7 @@ def poke(self, context) -> bool:
153
159
python_callable = lambda ** _ : None , # dummy function that does nothing
154
160
on_success_callback = [
155
161
send_slack_notification_partial (
156
- text = "ApogeeReduction pipeline completed successfully for SJD {{ ti.xcom_pull(task_ids='setup.mjd') }} (night of {{ (ds | string | to_datetime - timedelta(days=1)).strftime('%Y-%m-%d ') }}). Both observatories processed."
162
+ text = "ApogeeReduction pipeline completed successfully for SJD {{ ti.xcom_pull(task_ids='setup.mjd') }} (night of {{ task_instance.xcom_pull(task_ids='setup.date_mjd ') }}). Both observatories processed."
157
163
)
158
164
],
159
165
dag = dag
0 commit comments