Skip to content

Commit

Permalink
pkp#9823 update the crontrol job processing via scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Aug 2, 2024
1 parent 4c31a12 commit 8da0da4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
10 changes: 4 additions & 6 deletions classes/core/PKPQueueProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* @file classes/core/PKPQueueProvider.php
*
Expand Down Expand Up @@ -76,10 +74,10 @@ public function getWorkerOptions(array $options = []): WorkerOptions
*/
public function runJobsViaDaemon(string $connection, string $queue, array $workerOptions = []): void
{
$worker = PKPContainer::getInstance()['queue.worker']; /** @var \Illuminate\Queue\Worker $worker */
$worker = $this->app->get('queue.worker'); /** @var \Illuminate\Queue\Worker $worker */

$worker
->setCache(app()->get('cache.store'))
->setCache($this->app->get('cache.store'))
->daemon(
$connection,
$queue,
Expand All @@ -98,9 +96,9 @@ public function runJobInQueue(): void
return;
}

$laravelContainer = PKPContainer::getInstance();
$worker = $this->app->get('queue.worker'); /** @var \Illuminate\Queue\Worker $worker */

$laravelContainer['queue.worker']->runNextJob(
$worker->runNextJob(
'database',
$job->queue ?? Config::getVar('queues', 'default_queue', 'queue'),
$this->getWorkerOptions()
Expand Down
23 changes: 17 additions & 6 deletions classes/task/ProcessQueueJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace PKP\task;

use APP\core\Application;
use PKP\config\Config;
use PKP\core\PKPContainer;
use PKP\queue\JobRunner;
Expand All @@ -38,28 +37,40 @@ public function getName(): string
*/
public function executeActions(): bool
{
if (Application::isUnderMaintenance() || !Config::getVar('queues', 'job_runner', true)) {
// If processing of queue jobs via scheduler is disbaled
// will not process any queue jobs via schedule taks
if (!Config::getVar('queues', 'schedule_job_process', true)) {
return true;
}

$jobQueue = app('pkpJobQueue');
$jobQueue = app('pkpJobQueue'); /** @var \PKP\core\PKPQueueProvider $jobQueue */

$jobBuilder = $jobQueue->getJobModelBuilder();

if ($jobBuilder->count() <= 0) {
return true;
}

// Executes all pending jobs when running the runScheduledTasks.php on the CLI
// When processing queue jobs vai schedule task in CLI mode
// will process a limited number of jobs at a single time
if (PKPContainer::getInstance()->runningInConsole('runScheduledTasks.php')) {
while ($jobBuilder->count()) {
$maxJobCountToProcess = (int)Config::getVar('queues', 'job_runner_max_jobs', 30);

while ($jobBuilder->count() && $maxJobCountToProcess) {
$jobQueue->runJobInQueue();
$maxJobCountToProcess = $maxJobCountToProcess - 1;
}

return true;
}

// Executes a limited number of jobs when processing a request
// If the job runner is enabled,
// Scheduler will not process any queue jobs when running in web request mode
if (Config::getVar('queues', 'job_runner', false)) {
return true;
}

// Executes a limited number of jobs when processing a via web request mode
(new JobRunner($jobQueue))
->withMaxExecutionTimeConstrain()
->withMaxJobsConstrain()
Expand Down

0 comments on commit 8da0da4

Please sign in to comment.