Skip to content

Commit

Permalink
Merge pull request #70 from lsst-camera-dh/LSSTTD-1527_bot-data_py_re…
Browse files Browse the repository at this point in the history
…tries

Lssttd 1527 bot data py retries
  • Loading branch information
jchiang87 authored Oct 9, 2020
2 parents ea707ea + e5f253e commit 12cb150
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
10 changes: 6 additions & 4 deletions harnessed_jobs/BOT_acq/v0/producer_BOT_acq.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import subprocess
import pathlib
import siteUtils

from bot_acq_retry import copy_exposure_symlinks

def copy_sequencer_files():
"""
Expand All @@ -27,7 +27,7 @@ def copy_sequencer_files():
subprocess.check_call(command, shell=True)
with open(json_file, 'r') as fd:
seq_paths = json.load(fd)
for key, value in seq_paths.items():
for _, value in seq_paths.items():
command = f'scp {value} .'
print(command)
subprocess.check_call(command, shell=True)
Expand All @@ -49,9 +49,11 @@ def copy_sequencer_files():
shutil.copy(bot_eo_acq_cfg, os.path.join('.', outfile))

copy_sequencer_files()
skip = copy_exposure_symlinks()

command = (f'/home/ccs/bot-data.py --symlink . --skip {skip} '
f'--run {run_number} {bot_eo_acq_cfg}')

command = '/home/ccs/bot-data.py --symlink . --run {} {}'\
.format(run_number, bot_eo_acq_cfg)
subprocess.check_call(command, shell=True)

pathlib.Path('PRESERVE_SYMLINKS').touch()
28 changes: 28 additions & 0 deletions python/bot_acq_retry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import glob

def copy_exposure_symlinks(copy_links=True):
"""
If the current job execution is a retry, there will be a previous
working directory with symlinks to the successful BOT exposures.
This function finds the last working directory by sorting on the
activityId directory names, copies the exposure symlinks to the
current directory and returns the number of symlinks it made.
If there is no previous working directory, zero is returned.
"""
current_dir = os.path.abspath('.').split('/')[-1]
try:
last_dir = sorted([_ for _ in glob.glob('../*')
if current_dir not in _])[-1]
except IndexError:
return 0

num_symlinks = 0
for item in glob.glob(os.path.join(last_dir, '*_[0-9]*')):
if os.path.islink(item):
exposure_name = os.path.basename(item)
num_symlinks += 1
if copy_links and not os.path.islink(exposure_name):
os.symlink(os.path.realpath(item), exposure_name)
return num_symlinks

0 comments on commit 12cb150

Please sign in to comment.