Skip to content

Commit

Permalink
Fix timers for jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaehn committed Jan 4, 2024
1 parent d7d8c08 commit cee8c44
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
15 changes: 14 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import os
import yaml
import logging

from jobs import tools
from pathlib import Path
from pathlib import Path
from datetime import datetime


class Config():
Expand Down Expand Up @@ -391,6 +393,17 @@ def format_duration(self, duration):
formatted_duration = f"{int(days)}d {int(hours)}h {int(minutes)}m {int(seconds)}s"
return formatted_duration

def init_time_logging(self, job):
launch_time = datetime.now()
self.log_job_status(job, 'START', launch_time)

return launch_time

def finish_time_logging(self, job, launch_time):
end_time = datetime.now()
duration = end_time - launch_time
self.log_job_status(job, 'FINISH', end_time, duration)

def get_dep_ids(self, job_name, add_dep=None):
"""Get dependency job ids for `job_name`"""

Expand Down
3 changes: 3 additions & 0 deletions jobs/geosp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def main(cfg):
Add GEOSP
"""
prepare_data.set_cfg_variables(cfg)
launch_time = cfg.init_time_logging("geosp")

#-----------------------------------------------------
# Add GEOSP to all meteo files
Expand Down Expand Up @@ -58,3 +59,5 @@ def main(cfg):
logging.info("Added GEOSP to file {}".format(merged_file))
# Rename file to get original file name
tools.rename_file(merged_file, src_file)

cfg.finish_time_logging("geosp", launch_time)
3 changes: 3 additions & 0 deletions jobs/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def main(cfg):
Object holding all user-configuration parameters as attributes.
"""
prepare_data.set_cfg_variables(cfg)
launch_time = cfg.init_time_logging("icon")

logfile = cfg.log_working_dir / "icon"
logfile_finish = cfg.log_finished_dir / "icon"
Expand Down Expand Up @@ -81,3 +82,5 @@ def main(cfg):
#
# if exitcode != 0:
# raise RuntimeError("sbatch returned exitcode {}".format(exitcode))

cfg.finish_time_logging("icon", launch_time)
3 changes: 3 additions & 0 deletions jobs/prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def main(cfg):
If any subprocess returns a non-zero exit code during execution.
"""
set_cfg_variables(cfg)
launch_time = cfg.init_time_logging("prepare_data")

if cfg.workflow_name.startswith('icon'):
logging.info('ICON input data (IC/BC)')
Expand Down Expand Up @@ -525,3 +526,5 @@ def main(cfg):
output_log=True)

logging.info("OK")

cfg.finish_time_logging("prepare_data", launch_time)
17 changes: 3 additions & 14 deletions run_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,11 @@ def run_chunk(cfg, force, resume):
logfile = cfg.log_working_dir / job
logfile_finish = cfg.log_finished_dir / job
tools.change_logfile(logfile)
job_launch_time = datetime.now()
cfg.log_job_status(job, 'START', job_launch_time)

# Submit the job
script = cfg.create_sbatch_script(job, logfile)
job_id = cfg.submit(job, script)

# Logging
job_end_time = datetime.now()
job_duration = job_end_time - job_launch_time
cfg.log_job_status(job, 'FINISH', job_end_time, job_duration)
# This needs to be done by the job
#shutil.copy(logfile, logfile_finish)

# wait for previous chunk to be done
cfg.wait_for_previous()
# cycle
Expand Down Expand Up @@ -496,8 +487,7 @@ def main():
)

if cfg.logging:
launch_time = datetime.now()
cfg.log_job_status('chain', 'START', launch_time)
launch_time = cfg.init_time_logging('chain')

# Check for restart compatibility and spinup
if 'restart' in cfg.workflow['features']:
Expand All @@ -516,9 +506,8 @@ def main():
run_chunk(cfg=cfg, force=args.force, resume=args.resume)

if cfg.logging:
end_time = datetime.now()
duration = end_time - launch_time
cfg.log_job_status('chain', 'FINISH', end_time, duration)
cfg.finish_time_logging('chain', launch_time)

print('>>> Finished the processing chain successfully <<<')


Expand Down

0 comments on commit cee8c44

Please sign in to comment.