Skip to content

Commit c6ba29f

Browse files
clean up
1 parent 5b6641d commit c6ba29f

2 files changed

Lines changed: 16 additions & 34 deletions

File tree

core/pioreactor/background_jobs/base.py

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,47 +1265,33 @@ def set_currently_dodging_od(self, value: bool) -> None:
12651265
return
12661266

12671267
self._dodging_init_called_once = True
1268+
self.currently_dodging_od = value
12681269

12691270
if value:
1270-
self._enter_dodging_mode()
1271+
self.logger.debug("Dodging enabled.")
12711272
else:
1272-
self._enter_continuous_mode()
1273-
1274-
def _enter_dodging_mode(self) -> None:
1275-
self.currently_dodging_od = True
1276-
self.logger.debug("Dodging enabled.")
1277-
1278-
if self.state == self.SLEEPING:
1273+
self.logger.debug("Dodging disabled; running continuously.")
12791274
self._event_is_dodging_od.set()
1280-
self._dodging_mode_startup_pending = True
1281-
return
12821275

1283-
self._start_dodging_operation()
1276+
if self.sneak_in_timer is not None:
1277+
self.sneak_in_timer.cancel()
1278+
self.sneak_in_timer = None
12841279

1285-
def _start_dodging_operation(self) -> None:
1286-
self._dodging_mode_startup_pending = False
1287-
self._event_is_dodging_od.clear()
1288-
self.initialize_dodging_operation() # user defined
1289-
self._setup_timer()
1290-
1291-
def _enter_continuous_mode(self) -> None:
1292-
self.currently_dodging_od = False
1293-
self.logger.debug("Dodging disabled; running continuously.")
1294-
self._event_is_dodging_od.set()
1295-
1296-
if self.sneak_in_timer is not None:
1297-
self.sneak_in_timer.cancel()
1298-
self.sneak_in_timer = None
1280+
self._start_current_dodging_mode_or_defer_until_ready()
12991281

1282+
def _start_current_dodging_mode_or_defer_until_ready(self) -> None:
13001283
if self.state == self.SLEEPING:
1284+
self._event_is_dodging_od.set()
13011285
self._dodging_mode_startup_pending = True
13021286
return
13031287

1304-
self._start_continuous_operation()
1305-
1306-
def _start_continuous_operation(self) -> None:
13071288
self._dodging_mode_startup_pending = False
1308-
self.initialize_continuous_operation() # user defined
1289+
if self.currently_dodging_od:
1290+
self._event_is_dodging_od.clear()
1291+
self.initialize_dodging_operation() # user defined
1292+
self._setup_timer()
1293+
else:
1294+
self.initialize_continuous_operation() # user defined
13091295

13101296
def set_enable_dodging_od(self, value: bool) -> None:
13111297
"""Turn dodging on/off based on user intent, then align mode with current OD state."""
@@ -1450,10 +1436,7 @@ def ready(self) -> None:
14501436
if not self._dodging_mode_startup_pending:
14511437
return
14521438

1453-
if self.currently_dodging_od:
1454-
self._start_dodging_operation()
1455-
else:
1456-
self._start_continuous_operation()
1439+
self._start_current_dodging_mode_or_defer_until_ready()
14571440

14581441

14591442
class BackgroundJobWithDodgingContrib(BackgroundJobWithDodging):

core/tests/test_background_job.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ def initialize_continuous_operation(self) -> None:
720720
job.ready()
721721

722722
assert job.continuous_operation_calls == 1
723-
assert not job._dodging_mode_startup_pending
724723

725724

726725
def test_dodging_post_init_timer_setup_failure_cleans_up_running_job(monkeypatch) -> None:

0 commit comments

Comments
 (0)