Skip to content

Commit 9787f90

Browse files
touhidurabirasmecher
authored andcommitted
pkp/pkp-lib#7105 Job processing via cron and worker with new configs and cypress test update
1 parent feba337 commit 9787f90

File tree

4 files changed

+64
-29
lines changed

4 files changed

+64
-29
lines changed

Jobs/Statistics/CompileUsageStatsFromTemporaryRecords.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ public function handle(): void
6464
} else {
6565
$message = __('usageStats.compileMetrics.error', ['filename' => $filename]);
6666
}
67-
$this->failed(new JobException($message));
68-
return;
67+
68+
throw new JobException($message);
6969
}
7070

71-
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /* @var TemporaryTotalsDAO $temporaryTotalsDao */
72-
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /* @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
73-
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /* @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
74-
$temporaryTitleInvestigationsDao = DAORegistry::getDAO('TemporaryTitleInvestigationsDAO'); /* @var TemporaryTitleInvestigationsDAO $temporaryTitleInvestigationsDao */
75-
$temporaryTitleRequestsDao = DAORegistry::getDAO('TemporaryTitleRequestsDAO'); /* @var TemporaryTitleRequestsDAO $temporaryTitleRequestsDao */
76-
$temporaryInstitutionDao = DAORegistry::getDAO('TemporaryInstitutionsDAO'); /* @var TemporaryInstitutionsDAO $temporaryInstitutionDao */
71+
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
72+
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
73+
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /** @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
74+
$temporaryTitleInvestigationsDao = DAORegistry::getDAO('TemporaryTitleInvestigationsDAO'); /** @var TemporaryTitleInvestigationsDAO $temporaryTitleInvestigationsDao */
75+
$temporaryTitleRequestsDao = DAORegistry::getDAO('TemporaryTitleRequestsDAO'); /** @var TemporaryTitleRequestsDAO $temporaryTitleRequestsDao */
76+
$temporaryInstitutionDao = DAORegistry::getDAO('TemporaryInstitutionsDAO'); /** @var TemporaryInstitutionsDAO $temporaryInstitutionDao */
7777

7878
$temporaryTotalsDao->deleteByLoadId($this->loadId);
7979
$temporaryItemInvestigationsDao->deleteByLoadId($this->loadId);
@@ -89,11 +89,11 @@ public function handle(): void
8989
*/
9090
protected function compileMetrics(): bool
9191
{
92-
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /* @var TemporaryTotalsDAO $temporaryTotalsDao */
93-
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /* @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
94-
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /* @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
95-
$temporaryTitleInvestigationsDao = DAORegistry::getDAO('TemporaryTitleInvestigationsDAO'); /* @var TemporaryTitleInvestigationsDAO $temporaryTitleInvestigationsDao */
96-
$temporaryTitleRequestsDao = DAORegistry::getDAO('TemporaryTitleRequestsDAO'); /* @var TemporaryTitleRequestsDAO $temporaryTitleRequestsDao */
92+
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
93+
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
94+
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /** @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
95+
$temporaryTitleInvestigationsDao = DAORegistry::getDAO('TemporaryTitleInvestigationsDAO'); /** @var TemporaryTitleInvestigationsDAO $temporaryTitleInvestigationsDao */
96+
$temporaryTitleRequestsDao = DAORegistry::getDAO('TemporaryTitleRequestsDAO'); /** @var TemporaryTitleRequestsDAO $temporaryTitleRequestsDao */
9797

9898
$temporaryTotalsDao->removeDoubleClicks(StatisticsHelper::COUNTER_DOUBLE_CLICK_TIME_FILTER_SECONDS);
9999
$temporaryItemInvestigationsDao->compileBookItemUniqueClicks();

config.TEMPLATE.inc.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,43 @@
560560
; Default queue to use when a job is added to the queue
561561
default_queue = "queue"
562562

563-
; Do not run jobs on shutdown
564-
; By default, jobs in the queue will be run during PHP's shutdown
565-
; function. Disable this if you want to run jobs through a separate
566-
; cron job or workers.
567-
disable_jobs_run_at_shutdown = Off
563+
; Whether or not to turn on the built-in job runner
564+
;
565+
; When enabled, jobs will be processed at the end of each web
566+
; request to the application.
567+
;
568+
; Use of the built-in job runner is highly discouraged for high-volume
569+
; sites. Instead, a worker daemon or cron job should be configured
570+
; to process jobs off the application's main thread.
571+
;
572+
; See: <link-to-documentation>
573+
;
574+
job_runner = On
575+
576+
; The maximum number of jobs to run in a single request when using
577+
; the built-in job runner.
578+
job_runner_max_jobs = 30
579+
580+
; The maximum number of seconds the built-in job runner should spend
581+
; running jobs in a single request.
582+
;
583+
; This should be less than the max_execution_time the server has
584+
; configured for PHP.
585+
;
586+
; Lower this setting if jobs are failing due to timeouts.
587+
job_runner_max_execution_time = 30
588+
589+
; The maximum consumerable memory that should be spent by the built-in
590+
; job runner when running jobs.
591+
;
592+
; Set as a percentage, such as 80%:
593+
;
594+
; job_runner_max_memory = 80
595+
;
596+
; Or set as a fixed value in megabytes:
597+
;
598+
; job_runner_max_memory = 128M
599+
;
600+
; When setting a fixed value in megabytes, this should be less than the
601+
; memory_limit the server has configured for PHP.
602+
job_runner_max_memory = 80

cypress/support/index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@ import '@foreachbe/cypress-tinymce'
2020

2121
require('cypress-failed-log')
2222

23-
// See https://stackoverflow.com/questions/58657895/is-there-a-reliable-way-to-have-cypress-exit-as-soon-as-a-test-fails/58660504#58660504
24-
function abortEarly() {
25-
if (this.currentTest.state === 'failed') {
26-
return cy.task('shouldSkip', true);
27-
}
28-
cy.task('shouldSkip').then(value => {
29-
if (value) this.skip();
30-
});
31-
}
23+
beforeEach(function() {
24+
cy.abortEarly(this);
25+
});
3226

33-
beforeEach(abortEarly);
34-
afterEach(abortEarly);
27+
afterEach(function() {
28+
cy.abortEarly(this);
29+
cy.runQueueJobs();
30+
});
3531

3632
before(() => {
3733
if (Cypress.browser.isHeaded) {

registry/scheduledTasks.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@
5454
<descr>Send a monthly reminder email to editors about their outstanding tasks</descr>
5555
<frequency day="1"/>
5656
</task>
57+
<task class="PKP\task\ProcessQueueJobs">
58+
<descr>Process pending queue jobs in the default queue driver and queue</descr>
59+
<frequency second="0"/>
60+
</task>
5761
</scheduled_tasks>

0 commit comments

Comments
 (0)