Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_deserialize_info(arq_redis: ArqRedis):
j = await arq_redis.enqueue_job('foobar', 1, 2)
assert JobStatus.queued == await j.status()
await arq_redis.set(job_key_prefix + j.job_id, b'invalid pickle data')
with pytest.raises(DeserializationError, match='unable to deserialize job'):
assert await j.info()
async def test_deserialize_result(arq_redis: ArqRedis, worker):
async def foobar(ctx, a, b):
return a + b
j = await arq_redis.enqueue_job('foobar', 1, 2)
assert JobStatus.queued == await j.status()
worker: Worker = worker(functions=[func(foobar, name='foobar')])
await worker.run_check()
assert await j.result(pole_delay=0) == 3
assert await j.result(pole_delay=0) == 3
info = await j.info()
assert info.args == (1, 2)
await arq_redis.set(result_key_prefix + j.job_id, b'invalid pickle data')
with pytest.raises(DeserializationError, match='unable to deserialize job result'):
assert await j.result(pole_delay=0) == 3
def deserialize_job(r: bytes, *, deserializer: Optional[Deserializer] = None) -> JobDef:
if deserializer is None:
deserializer = pickle.loads
try:
d = deserializer(r)
return JobDef(
function=d['f'],
args=d['a'],
kwargs=d['k'],
job_try=d['t'],
enqueue_time=ms_to_datetime(d['et']),
score=None,
)
except Exception as e:
raise DeserializationError('unable to deserialize job') from e
try:
d = deserializer(r)
return JobResult(
job_try=d['t'],
function=d['f'],
args=d['a'],
kwargs=d['k'],
enqueue_time=ms_to_datetime(d['et']),
score=None,
success=d['s'],
result=d['r'],
start_time=ms_to_datetime(d['st']),
finish_time=ms_to_datetime(d['ft']),
)
except Exception as e:
raise DeserializationError('unable to deserialize job result') from e
def deserialize_job_raw(r: bytes, *, deserializer: Optional[Deserializer] = None) -> tuple:
if deserializer is None:
deserializer = pickle.loads
try:
d = deserializer(r)
return d['f'], d['a'], d['k'], d['t'], d['et']
except Exception as e:
raise DeserializationError('unable to deserialize job') from e