Skip to content

Commit

Permalink
Check now for bootstrax_state instead. Not sure about the 'else' in l…
Browse files Browse the repository at this point in the history
….362.
  • Loading branch information
mflierm committed Apr 20, 2022
1 parent b3e1d91 commit 59dedd2
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions bin/bootstrax
Original file line number Diff line number Diff line change
Expand Up @@ -345,22 +345,26 @@ def main():
elif args.process:
t_start = now()
number = args.process

# Check whether the run is already processed
bootstrax_state = run_col.find_one({'number': number}, projection={'bootstrax': True}).get('bootstrax', {}).get{'state', 'no-state')
if args.production and bootstrax_state in ['done','processing','considering']:
message = f"It looks like run {number} is already processed."
log_warning(message, priority='fatal')
raise ValueError(message)

rd = consider_run({'number': number})
if rd is None:
message = f"Trying to process single run but no run numbered {number} exists"
log_warning(message, priority='fatal')
raise ValueError(message)
if args.production:
if not rd['data'][0].get('type','no_type') == 'live':
message = f"Live data does not exist. Maybe run {number} is already processed?"
log_warning(message, priority='fatal')
raise ValueError(message)
else:
set_state('busy')
process_run(rd)
log.info(
f'bootstrax ({hostname}) finished run {number} in {(now() - t_start).seconds} seconds')
wait_on_delete_thread()

else:
set_state('busy')
process_run(rd)
log.info(
f'bootstrax ({hostname}) finished run {number} in {(now() - t_start).seconds} seconds')
wait_on_delete_thread()

else:
# Start processing
Expand Down

2 comments on commit 59dedd2

@mflierm
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoranAngevaare New attempt (thanks for the suggestions)! I'm always a bit confused by 'else' statements, in this case about the one in l.362. What do you think? :)

@JoranAngevaare
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mflierm , looks like you can open (your first?) PR to straxen!

The else doesn't hurt/add anything here. There is a raise ValueError at the and of the if so there is no way you will not be in the else regime.

In other words, these two blocks are identical in any way. The second if preferable since it's clearer (and shorter)

a = False
if not a:
   raise ValueError
else:
   bla(a) # Assume `a` is true
a = False
if not a:
   raise ValueError
bla(a) # Assume `a` is true

Please sign in to comment.