forked from shaba/openuds
small fixes on tasks
This commit is contained in:
parent
9cb9fc6de1
commit
2dc1634004
@ -46,7 +46,7 @@ class Job(Environmentable):
|
||||
friendly_name = 'Unknown'
|
||||
|
||||
@classmethod
|
||||
def setup(cls):
|
||||
def setup(cls: typing.Type['Job']) -> None:
|
||||
"""
|
||||
Sets ups frequency from configuration values
|
||||
"""
|
||||
@ -57,14 +57,14 @@ class Job(Environmentable):
|
||||
except Exception as e:
|
||||
logger.error('Error setting default frequency for %s ()%s. Got default value of %s', cls, e, cls.frecuency)
|
||||
|
||||
def execute(self):
|
||||
def execute(self) -> None:
|
||||
try:
|
||||
self.run()
|
||||
except Exception:
|
||||
logger.exception('Job %s raised an exception:', self.__class__)
|
||||
|
||||
def run(self):
|
||||
def run(self) -> None:
|
||||
"""
|
||||
You must provide your own "run" method to do whatever you need
|
||||
"""
|
||||
logging.debug("Base run of job called for class")
|
||||
logging.debug("Base run of job called for class %s", self.__class__)
|
||||
|
@ -44,8 +44,11 @@ from uds.core.util.config import GlobalConfig
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class BaseThread(threading.Thread):
|
||||
def notifyTermination(self):
|
||||
raise NotImplementedError
|
||||
|
||||
class SchedulerThread(threading.Thread):
|
||||
class SchedulerThread(BaseThread):
|
||||
def run(self):
|
||||
Scheduler.scheduler().run()
|
||||
|
||||
@ -53,7 +56,7 @@ class SchedulerThread(threading.Thread):
|
||||
Scheduler.scheduler().notifyTermination()
|
||||
|
||||
|
||||
class DelayedTaskThread(threading.Thread):
|
||||
class DelayedTaskThread(BaseThread):
|
||||
def run(self):
|
||||
DelayedTaskRunner.runner().run()
|
||||
|
||||
@ -78,12 +81,12 @@ class TaskManager:
|
||||
TaskManager.keepRunning = False
|
||||
|
||||
@staticmethod
|
||||
def registerJob(jobType: typing.Type[jobs.Job]):
|
||||
def registerJob(jobType: typing.Type[jobs.Job]) -> None:
|
||||
jobName = jobType.friendly_name
|
||||
jobs.factory().insert(jobName, jobType)
|
||||
|
||||
@staticmethod
|
||||
def registerScheduledTasks():
|
||||
def registerScheduledTasks() -> None:
|
||||
|
||||
logger.info("Registering sheduled tasks")
|
||||
|
||||
@ -91,7 +94,7 @@ class TaskManager:
|
||||
from uds.core import workers # @UnusedImport pylint: disable=unused-import
|
||||
|
||||
@staticmethod
|
||||
def run():
|
||||
def run() -> None:
|
||||
TaskManager.keepRunning = True
|
||||
|
||||
# Don't know why, but with django 1.8, must "reset" connections so them do not fail on first access...
|
||||
@ -108,7 +111,9 @@ class TaskManager:
|
||||
|
||||
logger.info('Starting %s schedulers and %s task executors', noSchedulers, noDelayedTasks)
|
||||
|
||||
threads = []
|
||||
threads: typing.List[BaseThread] = []
|
||||
thread: BaseThread
|
||||
|
||||
for _ in range(noSchedulers):
|
||||
thread = SchedulerThread()
|
||||
thread.start()
|
||||
|
Loading…
Reference in New Issue
Block a user