Skip to content

Commit 1980826

Browse files
committed
Some cleaning tasks are not needed anymore
1 parent 6e1a900 commit 1980826

2 files changed

Lines changed: 0 additions & 133 deletions

File tree

docs/jobs-maintenance.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ SCHEDULER_TASKS = [
3030
"interval": 3600
3131
},
3232
33-
# This will requeue jobs 'lost' between redis.blpop() and mongo.update(status=started).
34-
# This can happen only when the worker is killed brutally in the middle of dequeue_jobs()
35-
{
36-
"path": "mrq.basetasks.cleaning.RequeueLostJobs",
37-
"params": {},
38-
"interval": 24 * 3600
39-
},
40-
4133
# This will clean the list of known queues in Redis. It will mostly remove empty queues
4234
# so that they are not displayed in the dashboard anymore.
4335
{

mrq/basetasks/cleaning.py

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -75,131 +75,6 @@ def run(self, params):
7575
return stats
7676

7777

78-
class RequeueRedisStartedJobs(Task):
79-
80-
""" Requeue jobs that were started in Redis but not in Mongo.
81-
82-
They could have been lost by a worker interrupt between
83-
redis.lpop and mongodb.update
84-
"""
85-
86-
max_concurrency = 1
87-
88-
def run(self, params):
89-
90-
redis_key_started = Queue.redis_key_started()
91-
92-
stats = {
93-
"fetched": 0,
94-
"requeued": 0
95-
}
96-
97-
# Fetch all the jobs started more than a minute ago - they should not
98-
# be in redis:started anymore
99-
job_ids = connections.redis.zrangebyscore(
100-
redis_key_started, "-inf", time.time() - params.get("timeout", 60))
101-
102-
# TODO this should be wrapped inside Queue or Worker
103-
# we shouldn't access these internals here
104-
queue_obj = Queue("default")
105-
unserialized_job_ids = queue_obj.unserialize_job_ids(job_ids)
106-
107-
for i, job_id in enumerate(job_ids):
108-
109-
queue = Job(unserialized_job_ids[i], start=False, fetch=False).fetch(
110-
full_data=True).data["queue"]
111-
112-
queue_obj = Queue(queue)
113-
114-
stats["fetched"] += 1
115-
116-
log.info("Requeueing %s on %s" % (unserialized_job_ids[i], queue))
117-
118-
# TODO LUA script & don't rpush if not in zset anymore.
119-
with connections.redis.pipeline(transaction=True) as pipeline:
120-
pipeline.zrem(redis_key_started, job_id)
121-
pipeline.rpush(queue_obj.redis_key, job_id)
122-
pipeline.execute()
123-
124-
stats["requeued"] += 1
125-
126-
return stats
127-
128-
129-
class RequeueLostJobs(Task):
130-
131-
""" Requeue jobs that were queued but don't appear in Redis anymore.
132-
133-
They could have been lost by a Redis flush or another severe issue
134-
"""
135-
136-
max_concurrency = 1
137-
138-
def run(self, params):
139-
140-
# If there are more than this much items on the queue, we don't try to check if our mongodb
141-
# jobs are still queued.
142-
max_queue_items = params.get("max_queue_items", 1000)
143-
144-
stats = {
145-
"fetched": 0,
146-
"requeued": 0
147-
}
148-
149-
# This was only checking in Redis and wasn't resistant to a redis-wide flush.
150-
# Doing Queue.all() is slower but covers more edge cases.
151-
# all_queues = Queue.all_known()
152-
153-
all_queues = Queue.all()
154-
155-
log.info("Checking %s queues" % len(all_queues))
156-
157-
for queue_name in all_queues:
158-
159-
queue = Queue(queue_name)
160-
queue_size = queue.size()
161-
162-
# If the queue is raw, the jobs were only stored in redis so they are lost for good.
163-
if queue.is_raw:
164-
continue
165-
166-
log.info("Checking queue %s" % queue_name)
167-
168-
if queue_size > max_queue_items:
169-
log.info("Stopping because queue %s has %s items" %
170-
(queue_name, queue_size))
171-
continue
172-
173-
queue_jobs_ids = set(queue.list_job_ids(limit=max_queue_items + 1))
174-
if len(queue_jobs_ids) >= max_queue_items:
175-
log.info(
176-
"Stopping because queue %s actually had more than %s items" %
177-
(queue_name, len(queue_jobs_ids)))
178-
continue
179-
180-
for job_data in connections.mongodb_jobs.mrq_jobs.find({
181-
"queue": queue_name,
182-
"status": "queued"
183-
}, projection={"_id": 1}).sort([["_id", 1]]):
184-
185-
stats["fetched"] += 1
186-
187-
if str(job_data["_id"]) in queue_jobs_ids:
188-
log.info("Found job %s on queue %s. Stopping" % (job_data["_id"], queue.id))
189-
break
190-
191-
# At this point, this job is not on the queue and we're sure
192-
# the queue is less than max_queue_items
193-
# We can safely requeue the job.
194-
log.info("Requeueing %s on %s" % (job_data["_id"], queue.id))
195-
196-
stats["requeued"] += 1
197-
job = Job(job_data["_id"])
198-
job.requeue(queue=queue_name)
199-
200-
return stats
201-
202-
20378
class MigrateKnownQueues(Task):
20479
"""
20580
Migrate known_queues from old set format to new zset

0 commit comments

Comments
 (0)