Skip to content

Commit

Permalink
Disable Celery heartbeat and manually close channel and connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrooijen committed Oct 15, 2024
1 parent 8831ad2 commit 6f90651
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions hirefire_resource/macro/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def job_queue_latency(*queues, broker_url=None):
else:
broker_url = "redis://localhost:6379/0"

app = Celery(broker=broker_url)
app = Celery(broker=broker_url, broker_heartbeat=0)

try:
with app.connection_or_acquire() as connection:
Expand All @@ -115,9 +115,10 @@ def job_queue_latency(*queues, broker_url=None):
fn = _job_queue_latency_rabbitmq

return max(fn(channel, queue) for queue in queues)

except OperationalError:
return 0
finally:
app.close()


async def async_job_queue_latency(*queues, broker_url=None):
Expand Down Expand Up @@ -251,17 +252,18 @@ def job_queue_size(*queues, broker_url=None):
else:
broker_url = "redis://localhost:6379/0"

app = Celery(broker=broker_url)
app = Celery(broker=broker_url, broker_heartbeat=0)

try:
with app.connection_or_acquire() as connection:
with connection.channel() as channel:
worker_task_count = _job_queue_size_worker(app, queues)
broker_task_count = _job_queue_size_broker(channel, queues)
return worker_task_count + broker_task_count

except OperationalError:
return 0
finally:
app.close()


async def async_job_queue_size(*queues, broker_url=None):
Expand Down

0 comments on commit 6f90651

Please sign in to comment.