|
|
@ -9,18 +9,15 @@ import time
|
|
|
|
import traceback
|
|
|
|
import traceback
|
|
|
|
import warnings
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING, Type, List, Dict, Any
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
|
|
|
from redis import Redis
|
|
|
|
|
|
|
|
from redis.client import Pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from datetime import timedelta
|
|
|
|
from datetime import timedelta
|
|
|
|
from enum import Enum
|
|
|
|
from enum import Enum
|
|
|
|
from uuid import uuid4
|
|
|
|
from uuid import uuid4
|
|
|
|
from random import shuffle
|
|
|
|
from random import shuffle
|
|
|
|
from typing import Callable, List, Optional
|
|
|
|
from typing import Callable, List, Optional, TYPE_CHECKING, Type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
|
|
|
from redis import Redis
|
|
|
|
|
|
|
|
from redis.client import Pipeline
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from signal import SIGKILL
|
|
|
|
from signal import SIGKILL
|
|
|
@ -47,8 +44,7 @@ from .exceptions import DeserializationError, DequeueTimeout, ShutDownImminentEx
|
|
|
|
from .job import Job, JobStatus
|
|
|
|
from .job import Job, JobStatus
|
|
|
|
from .logutils import setup_loghandlers
|
|
|
|
from .logutils import setup_loghandlers
|
|
|
|
from .queue import Queue
|
|
|
|
from .queue import Queue
|
|
|
|
from .registry import FailedJobRegistry, StartedJobRegistry, clean_registries
|
|
|
|
from .registry import StartedJobRegistry, clean_registries
|
|
|
|
from .results import Result
|
|
|
|
|
|
|
|
from .scheduler import RQScheduler
|
|
|
|
from .scheduler import RQScheduler
|
|
|
|
from .suspension import is_suspended
|
|
|
|
from .suspension import is_suspended
|
|
|
|
from .timeouts import JobTimeoutException, HorseMonitorTimeoutException, UnixSignalDeathPenalty
|
|
|
|
from .timeouts import JobTimeoutException, HorseMonitorTimeoutException, UnixSignalDeathPenalty
|
|
|
@ -139,7 +135,7 @@ class Worker:
|
|
|
|
worker_keys = get_keys(queue=queue, connection=connection)
|
|
|
|
worker_keys = get_keys(queue=queue, connection=connection)
|
|
|
|
workers = [
|
|
|
|
workers = [
|
|
|
|
cls.find_by_key(
|
|
|
|
cls.find_by_key(
|
|
|
|
as_text(key), connection=connection, job_class=job_class, queue_class=queue_class, serializer=serializer
|
|
|
|
key, connection=connection, job_class=job_class, queue_class=queue_class, serializer=serializer
|
|
|
|
)
|
|
|
|
)
|
|
|
|
for key in worker_keys
|
|
|
|
for key in worker_keys
|
|
|
|
]
|
|
|
|
]
|
|
|
@ -1081,21 +1077,7 @@ class Worker:
|
|
|
|
started_job_registry.remove(job, pipeline=pipeline)
|
|
|
|
started_job_registry.remove(job, pipeline=pipeline)
|
|
|
|
|
|
|
|
|
|
|
|
if not self.disable_default_exception_handler and not retry:
|
|
|
|
if not self.disable_default_exception_handler and not retry:
|
|
|
|
failed_job_registry = FailedJobRegistry(
|
|
|
|
job._handle_failure(exc_string, pipeline=pipeline)
|
|
|
|
job.origin, job.connection, job_class=self.job_class, serializer=job.serializer
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
# Exception should be saved in job hash if server
|
|
|
|
|
|
|
|
# doesn't support Redis streams
|
|
|
|
|
|
|
|
_save_exc_to_job = not self.supports_redis_streams
|
|
|
|
|
|
|
|
failed_job_registry.add(
|
|
|
|
|
|
|
|
job,
|
|
|
|
|
|
|
|
ttl=job.failure_ttl,
|
|
|
|
|
|
|
|
exc_string=exc_string,
|
|
|
|
|
|
|
|
pipeline=pipeline,
|
|
|
|
|
|
|
|
_save_exc_to_job=_save_exc_to_job,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if self.supports_redis_streams:
|
|
|
|
|
|
|
|
Result.create_failure(job, job.failure_ttl, exc_string=exc_string, pipeline=pipeline)
|
|
|
|
|
|
|
|
with suppress(redis.exceptions.ConnectionError):
|
|
|
|
with suppress(redis.exceptions.ConnectionError):
|
|
|
|
pipeline.execute()
|
|
|
|
pipeline.execute()
|
|
|
|
|
|
|
|
|
|
|
@ -1142,19 +1124,8 @@ class Worker:
|
|
|
|
|
|
|
|
|
|
|
|
result_ttl = job.get_result_ttl(self.default_result_ttl)
|
|
|
|
result_ttl = job.get_result_ttl(self.default_result_ttl)
|
|
|
|
if result_ttl != 0:
|
|
|
|
if result_ttl != 0:
|
|
|
|
self.log.debug('Setting job %s status to finished', job.id)
|
|
|
|
self.log.debug(f"Saving job {job.id}'s successful execution result")
|
|
|
|
job.set_status(JobStatus.FINISHED, pipeline=pipeline)
|
|
|
|
job._handle_success(result_ttl, pipeline=pipeline)
|
|
|
|
# Result should be saved in job hash only if server
|
|
|
|
|
|
|
|
# doesn't support Redis streams
|
|
|
|
|
|
|
|
include_result = not self.supports_redis_streams
|
|
|
|
|
|
|
|
# Don't clobber user's meta dictionary!
|
|
|
|
|
|
|
|
job.save(pipeline=pipeline, include_meta=False, include_result=include_result)
|
|
|
|
|
|
|
|
if self.supports_redis_streams:
|
|
|
|
|
|
|
|
Result.create(
|
|
|
|
|
|
|
|
job, Result.Type.SUCCESSFUL, return_value=job._result, ttl=result_ttl, pipeline=pipeline
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
finished_job_registry = queue.finished_job_registry
|
|
|
|
|
|
|
|
finished_job_registry.add(job, result_ttl, pipeline)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
job.cleanup(result_ttl, pipeline=pipeline, remove_from_queue=False)
|
|
|
|
job.cleanup(result_ttl, pipeline=pipeline, remove_from_queue=False)
|
|
|
|
self.log.debug('Removing job %s from StartedJobRegistry', job.id)
|
|
|
|
self.log.debug('Removing job %s from StartedJobRegistry', job.id)
|
|
|
|