def is_worker_running(**kwargs): """ Return True if the background worker process is oprational """ clusters = Stat.get_all() if len(clusters) > 0: # TODO - Introspect on any cluster information return True """ Sometimes Stat.get_all() returns []. In this case we have the 'heartbeat' task running every 15 minutes. Check to see if we have a result within the last 20 minutes """ now = datetime.now() past = now - timedelta(minutes=20) results = Success.objects.filter( func='InvenTree.tasks.heartbeat', started__gte=past ) # If any results are returned, then the background worker is running! return results.exists()
def get_current_task(): clusters = Stat.get_all() current_tasks = CurrentTask.objects.all() if not clusters or clusters[0].status == 'Stopped': [current_task.delete() for current_task in current_tasks] current_tasks = [] now = datetime.datetime.now(tz=datetime.timezone.utc) tasks = [] for task in current_tasks: if task.ended: task.delete() else: running_for = (now - task.started).seconds progress = '{}/{}'.format(task.progress_current, task.progress_max) tasks.append({ 'action': task.name, 'running_for': running_for, 'progress': progress }) if task.progress_current == task.progress_max: task.ended = True task.save() return tasks
def test_bad_secret(r, monkeypatch): list_key = 'test_bad_secret' async('math.copysign', 1, -1, list_key=list_key) stop_event = Event() stop_event.set() start_event = Event() s = Sentinel(stop_event, start_event, list_key=list_key, start=False) Stat(s).save() # change the SECRET monkeypatch.setattr(Conf, "SECRET_KEY", "OOPS") stat = Stat.get_all(r) assert len(stat) == 0 assert Stat.get(s.parent_pid, r) is None task_queue = Queue() pusher(task_queue, stop_event, list_key=list_key, r=r) result_queue = Queue() task_queue.put('STOP') worker(task_queue, result_queue, Value('f', -1), ) assert result_queue.qsize() == 0 r.delete(list_key)
def test_bad_secret(r, monkeypatch): list_key = 'test_bad_secret' async ('math.copysign', 1, -1, list_key=list_key) stop_event = Event() stop_event.set() start_event = Event() s = Sentinel(stop_event, start_event, list_key=list_key, start=False) Stat(s).save() # change the SECRET monkeypatch.setattr(Conf, "SECRET_KEY", "OOPS") stat = Stat.get_all(r) assert len(stat) == 0 assert Stat.get(s.parent_pid, r) is None task_queue = Queue() pusher(task_queue, stop_event, list_key=list_key, r=r) result_queue = Queue() task_queue.put('STOP') worker( task_queue, result_queue, Value('f', -1), ) assert result_queue.qsize() == 0 r.delete(list_key)