cleanup scheduler
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
		| @ -405,7 +405,7 @@ class _PostgresConsumer(Consumer): | ||||
|         # Automatically purge messages on average every n iterations. | ||||
|         # We manually set the timeout to 30s, so we need to divide by 30 to | ||||
|         # get the number of actual iterations. | ||||
|         iterations = Conf().task_purge_interval // 30 | ||||
|         iterations = int(Conf().task_purge_interval / 30) | ||||
|         if randint(0, iterations):  # nosec | ||||
|             return | ||||
|         self.logger.debug("Running garbage collector") | ||||
|  | ||||
| @ -108,8 +108,7 @@ class SchedulerMiddleware(Middleware): | ||||
|                 "When using the scheduler, DRAMATIQ.schedule_class must be set." | ||||
|             ) | ||||
|  | ||||
|         self.scheduler_stop_event = Event() | ||||
|         self.scheduler: Scheduler = import_string(Conf().scheduler_class)(self.scheduler_stop_event) | ||||
|         self.scheduler: Scheduler = import_string(Conf().scheduler_class)() | ||||
|  | ||||
|     def after_process_boot(self, broker: Broker): | ||||
|         self.scheduler.broker = broker | ||||
|  | ||||
| @ -17,9 +17,8 @@ from django_dramatiq_postgres.models import ScheduleBase | ||||
| class Scheduler(Thread): | ||||
|     broker: Broker | ||||
|  | ||||
|     def __init__(self, stop_event: Event, *args, **kwargs): | ||||
|     def __init__(self, *args, **kwargs): | ||||
|         super().__init__(*args, **kwargs) | ||||
|         self.stop_event = stop_event | ||||
|         self.logger = get_logger(__name__, type(self)) | ||||
|  | ||||
|     @cached_property | ||||
| @ -53,11 +52,10 @@ class Scheduler(Thread): | ||||
|         return count | ||||
|  | ||||
|     def run(self): | ||||
|         while not self.stop_event.is_set(): | ||||
|             with self._lock() as lock_acquired: | ||||
|                 if not lock_acquired: | ||||
|                     self.logger.debug("Could not acquire lock, skipping scheduling") | ||||
|                     return | ||||
|                 count = self._run() | ||||
|                 self.logger.info(f"Sent {count} scheduled tasks") | ||||
|             sleep(Conf().scheduler_interval) | ||||
|         with self._lock() as lock_acquired: | ||||
|             if not lock_acquired: | ||||
|                 self.logger.debug("Could not acquire lock, skipping scheduling") | ||||
|                 return | ||||
|             count = self._run() | ||||
|             self.logger.info(f"Sent {count} scheduled tasks") | ||||
|         sleep(Conf().scheduler_interval) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Marc 'risson' Schmitt
					Marc 'risson' Schmitt