Skip to content

Commit e0e1f09

Browse files
committed
fixing linting, working on variable log length
1 parent 005e188 commit e0e1f09

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

arq/jobs.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import msgpack
1010

11-
from .utils import ellipsis, from_unix_ms, timestamp, to_unix_ms
11+
from .utils import DEFAULT_CURTAIL, ellipsis, from_unix_ms, timestamp, to_unix_ms
1212

1313
__all__ = ['JobSerialisationError', 'Job', 'DatetimeJob']
1414

@@ -68,7 +68,7 @@ def _encode(cls, data) -> bytes:
6868
def _decode(cls, data: bytes):
6969
return msgpack.unpackb(data, object_hook=cls.msgpack_object_hook, encoding='utf8')
7070

71-
def __str__(self):
71+
def to_string(self, args_curtail=DEFAULT_CURTAIL):
7272
arguments = ''
7373
if self.args:
7474
arguments = ', '.join(map(str, self.args))
@@ -77,7 +77,10 @@ def __str__(self):
7777
arguments += ', '
7878
arguments += ', '.join('{}={!r}'.format(*kv) for kv in sorted(self.kwargs.items()))
7979

80-
return '{s.class_name}.{s.func_name}({args})'.format(s=self, args=ellipsis(arguments))
80+
return '{s.class_name}.{s.func_name}({args})'.format(s=self, args=ellipsis(arguments, args_curtail))
81+
82+
def __str__(self):
83+
return self.to_string()
8184

8285
def __repr__(self):
8386
return '<Job {} on {}>'.format(self, self.queue)

arq/utils.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ def gen_random(length: int=20) -> bytes:
149149
return base64.urlsafe_b64encode(os.urandom(length))[:length]
150150

151151

152-
def ellipsis(s: str, length: int=80) -> str:
152+
DEFAULT_CURTAIL = 80
153+
154+
155+
def ellipsis(s: str, length: int=DEFAULT_CURTAIL) -> str:
153156
"""
154157
Truncate a string and add an ellipsis (three dots) to the end if it was too long
155158

arq/worker.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
from multiprocessing import Process
1616
from signal import Signals # type: ignore
1717

18-
from .logs import default_log_config
1918
from .jobs import Job
19+
from .logs import default_log_config
20+
from .main import Actor # noqa
2021
from .utils import RedisMixin, ellipsis, gen_random, timestamp
2122

2223
__all__ = ['BaseWorker', 'RunWorkerProcess', 'StopJob', 'import_string']
@@ -42,7 +43,7 @@ class BadJob(ArqError):
4243

4344

4445
class StopJob(ArqError):
45-
def __init__(self, reason: str='-', warning: bool=False):
46+
def __init__(self, reason: str='', warning: bool=False) -> None:
4647
self.warning = warning
4748
super().__init__(reason)
4849

@@ -97,7 +98,7 @@ def __init__(self, *,
9798

9899
self.jobs_complete, self.jobs_failed, self.jobs_timed_out = 0, 0, 0
99100
self._task_exception = None # type: Exception
100-
self._shadow_lookup = {} # type: Dict[str, object] # TODO
101+
self._shadow_lookup = {} # type: Dict[str, Actor]
101102
self.start = None # type: float
102103
self.last_health_check = 0
103104
self.running = True
@@ -363,10 +364,10 @@ def handle_prepare_exc(self, msg: str):
363364
@classmethod
364365
def handle_stop_job(cls, started_at: float, exc: StopJob, j: Job):
365366
if exc.warning:
366-
msg, logger = '%-4s ran in%7.3fs . %s: Stopped Warning, %s', jobs_logger.warning
367+
msg, logger = '%-4s ran in%7.3fs %s.%s ● Stopped Warning %s', jobs_logger.warning
367368
else:
368-
msg, logger = '%-4s ran in%7.3fs . %s: Stopped, %s', jobs_logger.info
369-
logger(msg, j.queue, timestamp() - started_at, j, exc)
369+
msg, logger = '%-4s ran in%7.3fs %s.%s ● Stopped %s', jobs_logger.info
370+
logger(msg, j.queue, timestamp() - started_at, j.class_name, j.func_name, exc)
370371

371372
@classmethod
372373
def handle_execute_exc(cls, started_at: float, exc: BaseException, j: Job):

tests/test_worker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def test_stop_job_normal(mock_actor_worker, caplog):
4141
actor, worker = mock_actor_worker
4242
await actor.stop_job_normal()
4343
await worker.run()
44-
assert ('arq.jobs INFO: dft ran in 0.0XXs . MockRedisDemoActor.stop_job_normal(): Stopped, '
44+
assert ('arq.jobs INFO: dft ran in 0.0XXs MockRedisDemoActor.stop_job_normalStopped '
4545
'stopping job normally') in caplog(('0.0\d\ds', '0.0XXs'))
4646

4747

@@ -50,7 +50,7 @@ async def test_stop_job_warning(mock_actor_worker, caplog):
5050
actor, worker = mock_actor_worker
5151
await actor.stop_job_warning()
5252
await worker.run()
53-
assert ('arq.jobs WARNING: dft ran in 0.0XXs . MockRedisDemoActor.stop_job_warning(): Stopped Warning, '
53+
assert ('arq.jobs WARNING: dft ran in 0.0XXs MockRedisDemoActor.stop_job_warningStopped Warning '
5454
'stopping job with warning') in caplog(('0.0\d\ds', '0.0XXs'))
5555

5656

0 commit comments

Comments
 (0)