In Craft 2, you used to be able to do something like this to find pending tasks:
craft()->tasks->getPendingTasks('MyPlugin_CustomTask')
In Craft 3 we of course now have the Queue, however there doesn't appear to be any specific methods like this for queue jobs given it's a bit different.
Using the Queue service I know I can get the current queue jobs without knowing any ID using getJobInfo():
$queue = Craft::$app->getQueue();
$jobs = $queue->getJobInfo();
$jobs is an array I can loop through to find any jobs I might be interested in. The description could be used but is there a better way?
foreach ($jobs as $job) {
if($job['description'] === 'something') {
// Do something
}
}
Alternatively, I could do a DB query on the queue table without looping, if I just wanted to get the count being greater than 0 as an e example.
$jobsQuery = (new Query())
->select('id')
->from(Table::QUEUE)
->where(['description', 'My job description'])
->all();
$jobsCount = count($jobsQuery) > 0;
if ($jobsCount) {
// Do something
}
Although both methods don't really seem that elegant to me.
Any suggestions of a better way or approach to this?