I'm trying to remove a scheduled job from ARQ (Python Redis job queue), but none of my approaches work. Here's what I've attempted:
Attempt: 1
arq_redis = await get_arq_redis()
await arq_redis.delete_job(schedule.job_id)
Attempt: 2
arq_redis = await get_arq_redis()
queued_jobs = await arq_redis.queued_jobs()
for job in queued_jobs:
if job.job_id == my_desired_job_id:
await job.delete()
Attempt: 3
for job in queued_jobs:
if job.job_id == schedule.job_id:
await job.abort()
Attempt: 4
for job_def in queued_jobs:
if job_def.job_id == schedule.job_id:
job = await arq_redis.get_job(job_def.job_id)
await job.abort()
The issue you're encountering stems from working with JobDef
objects (from queued_jobs()
) which are essentially read-only. To properly abort a scheduled job in ARQ, you need to work with Job
objects instead.
Here's the correct approach:
arq_redis = await get_arq_redis()
job = Job(job_id=your_job_id, redis=arq_redis)
status = await job.abort()
delete_job()
isn't the correct method for aborting scheduled jobsJobDef
objects from queued_jobs()
, which don't support direct modificationfrom arq.jobs import Job
async def cancel_scheduled_job(job_id: str):
arq_redis = await get_arq_redis()
job = Job(job_id=job_id, redis=arq_redis)
return await job.abort()
# Usage:
success = await cancel_scheduled_job("your-job-id-here")
abort()
method returns a boolean indicating successThis approach properly creates a Job
instance that can interact with the Redis queue to abort the scheduled task.