End of night shutdown improvements.#407
Conversation
A number of fixes and changes to account for situation when on valid observations are found but we don't want to shut down the state machine. * If scheduler has a list of `observations` then it `has_valid_observations`. which is True when starting. Process: * `scheduling` state calls `observatory.get_observation()` * `get_observation` first checks if `has_valid_observations is False` if so it will reread the field list. * `get_observation` either returns an observation or, if none found, calls `clear_available_observations`, making `has_valid_observations = False`. * If no observation is returned to `scheduling` state, send to `parking` (then to `sleeping`). * In `sleeping`, if `has_valid_observations is False` then sleep for an hour then try again (or shut down if `run_once` is specified). If `has_valid_observations is True` and it is safe and dark, shut down because of unknown error. Other changes: * Remove `reread_fields_file` from dispatch scheduler as it is handled at the `observatory` level by `observatory.get_observation`. * Misc small fixes
Codecov Report
@@ Coverage Diff @@
## develop #407 +/- ##
==========================================
+ Coverage 69.25% 69.3% +0.05%
==========================================
Files 60 60
Lines 4774 4806 +32
Branches 659 665 +6
==========================================
+ Hits 3306 3331 +25
- Misses 1292 1298 +6
- Partials 176 177 +1
Continue to review full report at Codecov.
|
jamessynge
left a comment
There was a problem hiding this comment.
LGTM, besides some nit and questions.
|
|
||
| # If it is dark and safe we shouldn't be in sleeping state | ||
| if pocs.is_dark() and pocs.is_safe(): | ||
| if pocs.observatory.scheduler.has_valid_observations and \ |
There was a problem hiding this comment.
pep8 strongly prefers wrapping with parens around expressions rather than using a backslash.
| if pocs.is_dark() and pocs.is_safe(): | ||
| if pocs.observatory.scheduler.has_valid_observations and \ | ||
| pocs.is_dark() and pocs.is_safe(): | ||
| if pocs.should_retry is False: |
There was a problem hiding this comment.
Property should_retry is very problematic. It looks like a property, but accessing it modifies its value!
There was a problem hiding this comment.
Yes, thanks for calling this out. It's also problematic in that it is never reset without stopping and starting whole system. So if it retries once per night by the third night it is out of retry attempts no matter what. Will fix.
| 'name': 'New Name', | ||
| 'position': '20h00m43.7135s +22d42m39.0645s', | ||
| 'priority': 50 | ||
| 'priority': 5000 |
There was a problem hiding this comment.
Out of curiosity, why the change in priority?
There was a problem hiding this comment.
Thanks for pointing this out too. I'm not sure doing what I did is quite what we want. Changing now.
| self.logger.debug("Getting observation for observatory") | ||
|
|
||
| # If observation list is empty or a reread is requested | ||
| if self.scheduler.has_valid_observations is False or \ |
There was a problem hiding this comment.
pep8 strongly prefers wrapping with parens around expressions rather than using a backslash.
Note: This changes some of the state behavior for how parking and retrying is handled. Housekeeping state will now only be called at the very end of an observing run (either in the morning when unsafe or when too many retry attempts). This moves some behavior from `sleeping` into `parked`. * Fix the `should_retry` so it does not modify values * Create a `reset_observing_run` method. Currenlty only resets number of retries * Other PR fixes
* Adding back the ability to reread fields file from the `get_observation` call so that a user can do it manually rather than relying on an empty observations list. But do it cleaner. * Test the rereading of a fields with same entires only with a new higher priority target * Skip duplicate observation entries rather than stopping with assertion error.
it for no reason and is also not testing what it says it should be testing.
|
I've removed a whole test in Feel weird about just removing a test but I think it is the right course of action. |
…s-clean-shutdown-390
Explicitly clear observations for test of no targets
| kwargs.get('reread_fields_file', False)): | ||
| self.scheduler.read_field_list() | ||
|
|
||
| self.scheduler.get_observation(*args, **kwargs) |
There was a problem hiding this comment.
This looks like it should return something. Why not return what get_observation returns?
There was a problem hiding this comment.
Good idea to make it explicit, but get_observation actually also sets current_observation, which is then returned. Should maybe think about renaming this.
| state_changed = self.goto_next_state() | ||
| except Exception as e: | ||
| self.logger.warning("Problem going to next state, exiting loop [{}]".format(e)) | ||
| self.logger.warning("Problem going from {} to {}, exiting loop [{!r}]".format( |
There was a problem hiding this comment.
Fine for now, but it would be nice to have a recovery mechanism, so that the system automatically tries to get to mount-parked/dome-closed/state-sleeping if things go bad, and then resumes... or waits until the next noon to restart.
There was a problem hiding this comment.
The state_changed is False it will do as you describe, which should be what happens under normal operations. We should probably do as you describe although I would want to do more testing and focus on it. Created #419 to address.
| pocs.next_state = 'housekeeping' | ||
| has_valid_observations = pocs.observatory.scheduler.has_valid_observations | ||
|
|
||
| if (has_valid_observations and pocs.is_safe() is False): |
There was a problem hiding this comment.
Parentheses not needed here.
| if (has_valid_observations and pocs.is_safe() is False): | ||
| pocs.say("Cleaning up for the night!") | ||
| pocs.next_state = 'housekeeping' | ||
| elif (has_valid_observations and pocs.is_safe()): |
| pocs.next_state = 'housekeeping' | ||
| has_valid_observations = pocs.observatory.scheduler.has_valid_observations | ||
|
|
||
| if (has_valid_observations and pocs.is_safe() is False): |
There was a problem hiding this comment.
Perhaps:
if has_valid_observations:
if not pocs.is_safe():
...
else: # pocs.is_safe
...
else: # not has_valid_observations
...* cleaning up code so parking logic is clearer
A number of fixes and changes to account for situation when no valid
observations are found but we don't want to shut down the state machine.
observationsthen ithas_valid_observations.which is True when starting.
Process:
schedulingstate callsobservatory.get_observation()get_observationfirst checks ifhas_valid_observations is Falseif so it will reread the field list.
get_observationeither returns an observation or, if none found,calls
clear_available_observations, makinghas_valid_observations = False.schedulingstate, send toparking(then tosleeping).sleeping, ifhas_valid_observations is Falsethen sleep for an hourthen try again (or shut down if
run_onceis specified).If
has_valid_observations is Trueand it is safe and dark, shut down becauseof unknown error.
Other changes:
reread_fields_filefrom dispatch scheduler as it is handled atthe
observatorylevel byobservatory.get_observation.Closes #390