| 1 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 2 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
"""Define job log filenames and option names.""" |
| 17 |
|
| 18 |
import os |
| 19 |
from typing import TYPE_CHECKING |
| 20 |
|
| 21 |
from cylc.flow.id import Tokens |
| 22 |
from cylc.flow.pathutil import get_workflow_run_job_dir |
| 23 |
|
| 24 |
|
| 25 |
if TYPE_CHECKING: |
| 26 |
from cylc.flow.cycling import PointBase |
| 27 |
|
| 28 |
|
| 29 |
# job log filenames. |
| 30 |
JOB_LOG_JOB = "job" |
| 31 |
JOB_LOG_OUT = "job.out" |
| 32 |
JOB_LOG_ERR = "job.err" |
| 33 |
JOB_LOG_ACTIVITY = "job-activity.log" |
| 34 |
JOB_LOG_STATUS = "job.status" |
| 35 |
JOB_LOG_XTRACE = "job.xtrace" # Note this is also defined in job.sh. |
| 36 |
|
| 37 |
JOB_LOG_OPTS = { |
| 38 |
'j': JOB_LOG_JOB, |
| 39 |
'o': JOB_LOG_OUT, |
| 40 |
'e': JOB_LOG_ERR, |
| 41 |
'a': JOB_LOG_ACTIVITY, |
| 42 |
's': JOB_LOG_STATUS, |
| 43 |
'x': JOB_LOG_XTRACE, |
| 44 |
} |
| 45 |
|
| 46 |
NN = "NN" |
| 47 |
|
| 48 |
|
| 49 |
def get_task_job_log( |
| 50 |
workflow: str, |
| 51 |
point: 'str | PointBase', |
| 52 |
name: str, |
| 53 |
submit_num: str | int | None = None, |
| 54 |
suffix: str | None = None, |
| 55 |
): |
| 56 |
"""Return the full job log path.""" |
| 57 |
args = [ |
| 58 |
get_workflow_run_job_dir(workflow), |
| 59 |
Tokens( |
| 60 |
cycle=str(point), |
| 61 |
task=name, |
| 62 |
job=str(submit_num or NN), |
| 63 |
).relative_id |
| 64 |
] |
| 65 |
if suffix is not None: |
| 66 |
args.append(suffix) |
| 67 |
return os.path.join(*args) |
| 68 |
|
| 69 |
|
| 70 |
def get_task_job_activity_log( |
| 71 |
workflow: str, |
| 72 |
point: 'str | PointBase', |
| 73 |
name: str, |
| 74 |
submit_num: str | int | None = None, |
| 75 |
): |
| 76 |
"""Shorthand for get_task_job_log(..., suffix="job-activity.log").""" |
| 77 |
return get_task_job_log( |
| 78 |
workflow, point, name, submit_num, JOB_LOG_ACTIVITY |
| 79 |
) |
| 80 |
|
| 81 |
|
| 82 |
def get_task_job_job_log( |
| 83 |
workflow: str, |
| 84 |
point: 'str | PointBase', |
| 85 |
name: str, |
| 86 |
submit_num: str | int | None = None, |
| 87 |
): |
| 88 |
"""Shorthand for get_task_job_log(..., suffix="job").""" |
| 89 |
return get_task_job_log(workflow, point, name, submit_num, JOB_LOG_JOB) |