Skip to content

Commit

Permalink
commands: remove unused WorkerMixin (bug 1927139)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzeid committed Jan 30, 2025
1 parent 5f797d9 commit eac59bd
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions src/lando/main/management/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +0,0 @@
from time import sleep

from lando.main.models.worker import Worker


class WorkerMixin:
@property
def _instance(self) -> Worker:
return Worker.objects.get(name=self.name)

def _start(self, max_loops: int | None = None, *args, **kwargs):
"""Run the main event loop."""
# NOTE: The worker will exit when max_loops is reached, or when the stop
# variable is changed to True.
loops = 0
while not self._instance.is_stopped:
if max_loops is not None and loops >= max_loops:
break
while self._instance.is_paused:
self.throttle(self._instance.sleep_seconds)
self.loop(*args, **kwargs)
loops += 1

self.stdout.write(f"{self} exited after {loops} loops.")

def throttle(self, seconds: int | None = None):
"""Sleep for a given number of seconds."""
sleep(seconds if seconds is not None else self._instance.throttle_seconds)

def start(self, max_loops: int | None = None):
"""Run setup sequence and start the event loop."""
if not self._instance.is_stopped:
self._start(max_loops=max_loops)

def loop(self, *args, **kwargs):
"""The main event loop."""
raise NotImplementedError()

0 comments on commit eac59bd

Please sign in to comment.