Answers.Body: <p>Yes, you can access the queue component using <code>\Craft::$app-&gt;getQueue()</code>. Keep in mind that this <em>may</em> return null or a non-compatible component depending on configuration, so make sure to check if the queue component is an instance of the <code>craft\queue\QueueInterface</code>.</p>
  <p>The default queue component (<a href="https://docs.craftcms.com/api/v3/craft-queue-queue.html" rel="nofollow noreferrer">craft\queue\Queue</a>) has all the methods you need to build your interface:</p>
  <ul>
  <li><a href="https://docs.craftcms.com/api/v3/craft-queue-queue.html#method-getjobinfo" rel="nofollow noreferrer">Queue::getJobInfo()</a> returns an array with information on all active queue jobs (up to the specified <code>$limit</code>).</li>
  <li><a href="https://docs.craftcms.com/api/v3/craft-queue-queue.html#method-release" rel="nofollow noreferrer">Queue::release()</a> to release a specific job or <a href="https://docs.craftcms.com/api/v3/craft-queue-queue.html#method-releaseall" rel="nofollow noreferrer">Queue::releaseAll()</a> to release all jobs.</li>
  <li><a href="https://docs.craftcms.com/api/v3/craft-queue-queue.html#method-retry" rel="nofollow noreferrer">Queue::retry()</a> to retry a specific job or <a href="https://docs.craftcms.com/api/v3/craft-queue-queue.html#method-retryall" rel="nofollow noreferrer">Queue::retryAll()</a> to retry all.</li>
  <li>… and so on.</li>
  </ul>
  <p>A good place to discover how Craft uses these core features are the CMS controllers. In this case, <a href="https://docs.craftcms.com/api/v3/craft-controllers-queuecontroller.html" rel="nofollow noreferrer">craft\controllers\QueueController</a> contains all the endpoints / actions used by the Queue Manager utility and will show you how Craft uses the service methods to build the interface.</p>
  <blockquote>
  <p>I have found on quicker intervals that the queue can get overwhelmed with jobs quicker than it is able to complete them eventually taking the site down as a whole.</p>
  </blockquote>
  <p>This is a bit troubling because the queue should never be able to take down the site. Make sure you're service supervisor gives the queue runner a low priority so it doesn't interfere with site requests. See the article <a href="https://nystudio107.com/blog/robust-queue-job-handling-in-craft-cms#solution-2-forge-daemons" rel="nofollow noreferrer">Robost queue job handling in Craft</a> for more information.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-17T09:02:06.490Z
Answers.LastActivityDate: 2021-11-17T09:02:06.490Z
Answers.UserDisplayName: MoritzLost
Body: <p>Is it possible in code to search for a job/list out all jobs?</p>
  <p>I have built a plugin that scans an external API and I want to scan on an interval as well as allow the user to fire off a manual scan. I have found on quicker intervals that the queue can get overwhelmed with jobs quicker than it is able to complete them eventually taking the site down as a whole.</p>
  <p>Is there any way to query the queue list for current jobs? either search by name or just get the full list so I can loop through them?</p>
  <p>also is it possible to release specific jobs or all jobs from code?</p>
  <p>Thanks for any help given</p>
  
Tags: <craft3><plugin-development><php><queue>
Title: Check for existing jobs in queue
ThreadText: # Check for existing jobs in queue
  
  (Asked by: username_0 on 2021-11-16)
  
  Is it possible in code to search for a job/list out all jobs?
  
  I have built a plugin that scans an external API and I want to scan on an interval as well as allow the user to fire off a manual scan. I have found on quicker intervals that the queue can get overwhelmed with jobs quicker than it is able to complete them eventually taking the site down as a whole.
  
  Is there any way to query the queue list for current jobs? either search by name or just get the full list so I can loop through them?
  
  also is it possible to release specific jobs or all jobs from code?
  
  Thanks for any help given
  
  **Tags:** craft3, plugin-development, php, queue
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-11-17. Score: 1
  
  Yes, you can access the queue component using `\Craft::$app->getQueue()`. Keep in mind that this *may* return null or a non-compatible component depending on configuration, so make sure to check if the queue component is an instance of the `craft\queue\QueueInterface`.
  
  The default queue component ([craft\queue\Queue](https://docs.craftcms.com/api/v3/craft-queue-queue.html)) has all the methods you need to build your interface:
  
  * [Queue::getJobInfo()](https://docs.craftcms.com/api/v3/craft-queue-queue.html#method-getjobinfo) returns an array with information on all active queue jobs (up to the specified `$limit`).
  * [Queue::release()](https://docs.craftcms.com/api/v3/craft-queue-queue.html#method-release) to release a specific job or [Queue::releaseAll()](https://docs.craftcms.com/api/v3/craft-queue-queue.html#method-releaseall) to release all jobs.
  * [Queue::retry()](https://docs.craftcms.com/api/v3/craft-queue-queue.html#method-retry) to retry a specific job or [Queue::retryAll()](https://docs.craftcms.com/api/v3/craft-queue-queue.html#method-retryall) to retry all.
  * … and so on.
  
  A good place to discover how Craft uses these core features are the CMS controllers. In this case, [craft\controllers\QueueController](https://docs.craftcms.com/api/v3/craft-controllers-queuecontroller.html) contains all the endpoints / actions used by the Queue Manager utility and will show you how Craft uses the service methods to build the interface.
  
  > I have found on quicker intervals that the queue can get overwhelmed with jobs quicker than it is able to complete them eventually taking the site down as a whole.
  
  This is a bit troubling because the queue should never be able to take down the site. Make sure you're service supervisor gives the queue runner a low priority so it doesn't interfere with site requests. See the article [Robost queue job handling in Craft](https://nystudio107.com/blog/robust-queue-job-handling-in-craft-cms#solution-2-forge-daemons) for more information.
  
  
  ---
  
  