-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #690 from douglasjacobsen/job-status-mod
Add a status-markers modifier
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
var/ramble/repos/builtin/modifiers/status-markers/modifier.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,71 @@ | ||
# Copyright 2022-2024 The Ramble Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
# option. This file may not be copied, modified, or distributed | ||
# except according to those terms. | ||
|
||
import os | ||
import llnl.util.filesystem as fs | ||
|
||
from ramble.modkit import * | ||
|
||
|
||
class StatusMarkers(BasicModifier): | ||
"""Modifier to create a marker file when the experiment has started and | ||
ended. | ||
This modifier will create a .started and .finished file within the | ||
experiment run dir. | ||
""" | ||
|
||
name = "status-markers" | ||
|
||
tags("status", "info") | ||
|
||
_started_marker = ".started" | ||
_finished_marker = ".finished" | ||
|
||
maintainers("douglasjacobsen") | ||
|
||
mode("standard", description="Standard execution mode") | ||
|
||
register_builtin( | ||
"write_started_marker", required=True, injection_method="prepend" | ||
) | ||
|
||
def write_started_marker(self): | ||
cmds = [ | ||
'echo "Started" &> {experiment_run_dir}/' + self._started_marker, | ||
"rm -f {experiment_run_dir}/" + self.finished_marker, | ||
] | ||
|
||
return cmds | ||
|
||
register_builtin( | ||
"write_finished_marker", required=True, injection_method="append" | ||
) | ||
|
||
def write_finished_marker(self): | ||
cmds = [ | ||
'echo "Finished" &> {experiment_run_dir}/' + self._finished_marker | ||
] | ||
|
||
return cmds | ||
|
||
register_phase( | ||
"clean_markers", pipeline="setup", run_after=["make_experiments"] | ||
) | ||
|
||
def _clean_markers(self, workspace, app_inst=None): | ||
exp_dir = self.expander.expand_var_name( | ||
app_inst.keywords.experiment_run_dir | ||
) | ||
|
||
started_marker = os.path.join(exp_dir, self._started_marker) | ||
finished_marker = os.path.join(exp_dir, self._finished_marker) | ||
|
||
for marker in [started_marker, finished_marker]: | ||
if os.path.isfile(marker): | ||
fs.force_remove(marker) |