Skip to content

Commit

Permalink
It does not seem to complain anymore, but it does not complain any less
Browse files Browse the repository at this point in the history
Signed-off-by: bghira <bghira@users.github.com>
  • Loading branch information
bghira committed Apr 4, 2023
1 parent ea597cd commit 6391e02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions discord_tron_master/classes/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ async def process_jobs(self):
logging.error(f"An error occurred while processing jobs for worker {self.worker_id}: {e}")
await asyncio.sleep(1) # Use 'await' for asynchronous sleep

def start(self):
# Use 'asyncio.create_task' to run the 'process_jobs' coroutine
self.worker_task = asyncio.create_task(self.process_jobs())

def monitor_worker(self):
async def monitor_worker(self):
logging.debug(f"Beginning worker monitoring for worker {self.worker_id}")
while True:
if self.worker_task is None or self.worker_task.done() and not self.terminate:
Expand All @@ -80,8 +76,9 @@ def monitor_worker(self):
logging.info("Worker is set to exit, and the time has come.")
break
# Sleep for a while before checking again
time.sleep(10)
await asyncio.sleep(10)

def start_monitoring_thread(self):
self.monitor_thread = threading.Thread(target=self.monitor_worker)
self.monitor_thread.start()
async def start_monitoring(self):
# Use 'asyncio.create_task' to run the 'process_jobs' and 'monitor_worker' coroutines
self.worker_task = asyncio.create_task(self.process_jobs())
self.monitor_task = asyncio.create_task(self.monitor_worker())
2 changes: 1 addition & 1 deletion discord_tron_master/classes/worker_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def register(self, payload: Dict[str, Any]) -> Dict:
worker = self.register_worker(worker_id, supported_job_types, hardware_limits, hardware)
self.queue_manager.register_worker(worker_id, supported_job_types)
worker.set_job_queue(self.queue_manager.queue_by_worker(worker))
worker.start_monitoring_thread()
await worker.start_monitoring() # Use 'await' to call the async 'start_monitoring' method
return {"success": True, "result": "Worker " + str(worker_id) + " registered successfully"}

async def unregister(self, payload: Dict[str, Any]) -> Dict:
Expand Down

0 comments on commit 6391e02

Please sign in to comment.