Skip to content

Commit

Permalink
push loggers to timers
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Nov 28, 2024
1 parent 5adaa62 commit bd6d28a
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Highlights
- new export dataset API. The datasets on the Export page are now provided via YAML files on the leader's disk. This makes it easy to add new datasets to that UI to be exported. These YAML files can be added to `~/.pioreactor/exportable_datasets`.
- new Export Data page in the UI. Preview datasets before you export them, and new partition options for the exported csvs.
- Plugins can now add datasets to the Export Data page. The plugin's datasets are automatically added to the Export Data page when installed.

#### Enhancements
- better error handling for failed OD blanks.
Expand Down
5 changes: 3 additions & 2 deletions pioreactor/background_jobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,8 @@ def _clear_caches(self) -> None:

def _check_for_duplicate_activity(self) -> None:
if is_pio_job_running(self.job_name) and not is_testing_env():
self.logger.warning(f"{self.job_name} is already running. Skipping")
raise RuntimeError(f"{self.job_name} is already running. Skipping")
self.logger.warning(f"{self.job_name} is already running. Skipping.")
raise RuntimeError(f"{self.job_name} is already running. Skipping.")

def __setattr__(self, name: str, value: t.Any) -> None:
super(_BackgroundJob, self).__setattr__(name, value)
Expand Down Expand Up @@ -1138,6 +1138,7 @@ def sneak_in(ads_interval, post_delay, pre_delay) -> None:
job_name=self.job_name,
args=(ads_interval, post_delay, pre_delay),
run_immediately=False,
logger=self.logger,
)

# TODO: shouldn't I just use run_after in `RepeatedTimer` instead of this?
Expand Down
1 change: 1 addition & 0 deletions pioreactor/background_jobs/dosing_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def set_duration(self, duration: Optional[float]) -> None:
job_name=self.job_name,
run_immediately=(not self.skip_first_run) or (self._latest_run_at is not None),
run_after=run_after,
logger=self.logger,
).start()

else:
Expand Down
4 changes: 2 additions & 2 deletions pioreactor/background_jobs/leader/mqtt_to_db_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def __init__(
for topic_to_table in topics_to_tables
]

self.timer = RepeatedTimer(60, self.publish_stats).start()
self.timer = RepeatedTimer(60, self.write_stats).start()

self.initialize_callbacks(topics_and_callbacks)

def publish_stats(self) -> None:
def write_stats(self) -> None:
with local_intermittent_storage(self.job_name) as c:
c["inserts_in_last_60s"] = self._inserts_in_last_60s

Expand Down
1 change: 1 addition & 0 deletions pioreactor/background_jobs/led_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def set_duration(self, duration: float) -> None:
job_name=self.job_name,
run_immediately=(not self.skip_first_run) or (self._latest_run_at is not None),
run_after=run_after,
logger=self.logger,
).start()

def run(self, timeout: float = 60.0) -> Optional[events.AutomationEvent]:
Expand Down
5 changes: 1 addition & 4 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ def pretty_version(info: tuple) -> str:
# we manually run a self_check outside of a thread first, as if there are
# problems detected, we may want to block and not let the job continue.
self.self_check_thread = RepeatedTimer(
4 * 60 * 60,
self.self_checks,
job_name=self.job_name,
run_immediately=True,
4 * 60 * 60, self.self_checks, job_name=self.job_name, run_immediately=True, logger=self.logger
).start()

self.add_pre_button_callback(self._republish_state)
Expand Down
1 change: 1 addition & 0 deletions pioreactor/background_jobs/od_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ def __init__(
self.record_from_adc,
job_name=self.job_name,
run_immediately=True,
logger=self.logger,
).start()

self.logger.debug(
Expand Down
1 change: 1 addition & 0 deletions pioreactor/background_jobs/stirring.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def __init__(
job_name=self.job_name,
run_immediately=True,
run_after=6,
logger=self.logger,
)

def initialize_rpm_to_dc_lookup(self) -> Callable:
Expand Down
1 change: 1 addition & 0 deletions pioreactor/background_jobs/temperature_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def __init__(
self.read_external_temperature,
job_name=self.job_name,
run_immediately=False,
logger=self.logger,
).start()

self.publish_temperature_timer = RepeatedTimer(
Expand Down
10 changes: 7 additions & 3 deletions pioreactor/utils/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def __init__(
job_name: t.Optional[str] = None,
run_immediately: bool = False,
run_after: t.Optional[float] = None,
logger=None,
args=(),
kwargs={},
) -> None:
Expand All @@ -107,9 +108,12 @@ def __init__(
self.function = function
self.args = args
self.kwargs = kwargs
self.logger = create_logger(
job_name or "RepeatedTimer"
) # TODO: I don't think this works as expected.
if logger is None:
self.logger = create_logger(
job_name or "RepeatedTimer"
) # TODO: I don't think this works as expected.
else:
self.logger = logger
self.is_paused = False
if run_after is not None:
assert run_after >= 0, "run_after should be non-negative."
Expand Down

0 comments on commit bd6d28a

Please sign in to comment.