Skip to content

Commit d2245cd

Browse files
authored
Force renew .dbtoken before workflow submission (#224)
* Force renew `.dbtoken` before workflow submission * Minor change * Simplification * Update README, and no pre-commit error
1 parent 0623cad commit d2245cd

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
language_version: python3
2323

2424
- repo: https://github.com/pycqa/docformatter
25-
rev: v1.7.5
25+
rev: master
2626
hooks:
2727
- id: docformatter
2828
additional_dependencies: [tomli]

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,9 @@ After installation and setting up the environment, it is time to submit jobs. Th
158158

159159
```
160160
[whoami@ap23 ~]$ outsource --help
161-
usage: Outsource [-h] --context CONTEXT --xedocs_version XEDOCS_VERSION [--image IMAGE]
162-
[--detector {all,tpc,muon_veto,neutron_veto}] [--workflow_id WORKFLOW_ID] [--ignore_processed]
163-
[--debug] [--from NUMBER_FROM] [--to NUMBER_TO] [--run [RUN ...]] [--runlist RUNLIST] [--rucio_upload]
164-
[--rundb_update] [--local_transfer]
161+
usage: Outsource [-h] --context CONTEXT --xedocs_version XEDOCS_VERSION [--image IMAGE] [--detector {all,tpc,muon_veto,neutron_veto}]
162+
[--workflow_id WORKFLOW_ID] [--ignore_processed] [--debug] [--from NUMBER_FROM] [--to NUMBER_TO] [--run [RUN ...]]
163+
[--runlist RUNLIST] [--rucio_upload] [--rundb_update] [--local_transfer] [--keep_dbtoken]
165164
166165
optional arguments:
167166
-h, --help show this help message and exit
@@ -171,20 +170,20 @@ optional arguments:
171170
--image IMAGE Singularity image. Accepts either a full path or a single name and assumes a format like this:
172171
/cvmfs/singularity.opensciencegrid.org/xenonnt/base-environment:{image}
173172
--detector {all,tpc,muon_veto,neutron_veto}
174-
Detector to focus on. If 'all' (default) will consider all three detectors. Otherwise pass a
175-
single one of 'tpc', 'neutron_veto', 'muon_veto'. Pairs of detectors not yet supported.
173+
Detector to focus on. If 'all' (default) will consider all three detectors. Otherwise pass a single one of
174+
'tpc', 'neutron_veto', 'muon_veto'. Pairs of detectors not yet supported.
176175
--workflow_id WORKFLOW_ID
177176
Custom workflow_id of workflow. If not passed, inferred from today's date.
178177
--ignore_processed Ignore runs that have already been processed
179-
--debug Debug mode. Does not automatically submit the workflow, and jobs do not update RunDB nor upload
180-
to rucio.
178+
--debug Debug mode. Does not automatically submit the workflow, and jobs do not update RunDB nor upload to rucio.
181179
--from NUMBER_FROM Run number to start with
182180
--to NUMBER_TO Run number to end with
183-
--run [RUN ...] Space separated specific run number(s) to process
181+
--run [RUN ...] Space separated specific run_id(s) to process
184182
--runlist RUNLIST Path to a runlist file
185183
--rucio_upload Upload data to rucio after processing
186184
--rundb_update Update RunDB after processing
187185
--local_transfer Transfer data to local after processing
186+
--keep_dbtoken Do not renew .dbtoken
188187
```
189188

190189
This script requires at minimum the name of context (which must reside in the cutax version installed in the environment you are in). If no other arguments are passed, this script will try to find all data that can be processed, and process it. Some inputs from the configuration file at environmental variable `XENON_CONFIG` are also used, specifically:

outsource/scripts/submit.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import os
12
import argparse
2-
from utilix import xent_collection, uconfig
3+
from utilix import xent_collection, uconfig, DB
34
from utilix.io import load_runlist
45
from utilix.config import setup_logger
56

@@ -77,8 +78,20 @@ def main():
7778
action="store_true",
7879
help="Transfer data to local after processing",
7980
)
81+
parser.add_argument(
82+
"--keep_dbtoken",
83+
dest="keep_dbtoken",
84+
action="store_true",
85+
help="Do not renew .dbtoken",
86+
)
8087
args = parser.parse_args()
8188

89+
if not args.keep_dbtoken:
90+
os.remove(os.path.join(os.environ["HOME"], ".dbtoken"))
91+
# Remove the cached DB instance and reinitialize it
92+
DB._instances = dict()
93+
DB()
94+
8295
if "development" in args.image:
8396
raise RuntimeError("Cannot use development images/container for processing!")
8497

outsource/submitter.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
import json
4+
import shutil
45
import getpass
56
from itertools import chain
67
from datetime import datetime
@@ -171,6 +172,10 @@ def __init__(
171172
self.outputs_dir = os.path.join(self.workflow_dir, "outputs")
172173
self.scratch_dir = os.path.join(self.workflow_dir, "scratch")
173174

175+
@property
176+
def dbtoken(self):
177+
return os.path.join(self.generated_dir, ".dbtoken")
178+
174179
@property
175180
def workflow(self):
176181
return os.path.join(self.generated_dir, "workflow.yml")
@@ -752,11 +757,11 @@ def _generate_workflow(self):
752757
xenon_config = File(".xenon_config")
753758
rc.add_replica("local", ".xenon_config", f"file://{uconfig.config_path}")
754759

755-
# token needed for DB connection
760+
# Token needed for DB connection
756761
token = File(".dbtoken")
757-
rc.add_replica(
758-
"local", ".dbtoken", "file://" + os.path.join(os.environ["HOME"], ".dbtoken")
759-
)
762+
# Avoid its change after the job submission
763+
shutil.copy(os.path.join(os.environ["HOME"], ".dbtoken"), self.dbtoken)
764+
rc.add_replica("local", ".dbtoken", f"file://{self.dbtoken}")
760765

761766
tarballs, tarball_paths = self.make_tarballs()
762767
for tarball, tarball_path in zip(tarballs, tarball_paths):

0 commit comments

Comments
 (0)