Question: List queued tasks with ActiveJob AsyncAdapter


List queued tasks with ActiveJob AsyncAdapter

Answers 1
Added at 2016-10-14 00:10

Is there a way I can see how many (maybe even inspect each job?) jobs are there remaining in the queue?

Answers to

List queued tasks with ActiveJob AsyncAdapter

nr: #1 dodano: 2016-10-14 01:10

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:


Above does the following:

  1. get your adapter
  2. get its instance_variable @scheduler, that points to
  3. instance of Concurrent::ThreadPoolExecutor (instance variable of Scheduler class - @async_executor)
  4. on which you can actually call the methods, described above (queue_length, scheduled_task_count and others)

Though I did not tested it, so make sure to double check for typos or whatsoever.

Source Show
◀ Wstecz