Is there a way I can see how many (maybe even inspect each job?) jobs are there remaining in the queue?
After some digging into source code here is what I found out:
ActiveJob::QueueAdapters::AsyncAdapter
uses a Concurrent Ruby thread pool to schedule and execute jobs.
When you initialize the adapter in your configuration, you pass executor options, which in turn happen to be arguments to initialize
method of
Concurrent::ThreadPoolExecutor
class.
Created instance of Concurrent::ThreadPoolExecutor
class has such methods, as:
queue_length
- The number of tasks in the queue awaiting execution.scheduled_task_count
- The number of tasks that have been scheduled for execution on the pool since construction.That said, I think something along these lines should do it for you:
ActiveJob::Base
.queue_adapter
.instance_variable_get(:@scheduler)
.instance_variable_get(:@async_executor)
.public_send(:queue_length)
Above does the following:
@scheduler
, that points to Concurrent::ThreadPoolExecutor
(instance variable of Scheduler
class - @async_executor
)queue_length
, scheduled_task_count
and others)Though I did not test it, so make sure to double check for typos or whatsoever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With