Skip to content

Commit

Permalink
Merge pull request pkp#4332 from touhidurabir/i9678_main
Browse files Browse the repository at this point in the history
pkp/pkp-lib#9678 Replacing task schedular with laravel scheduler
  • Loading branch information
touhidurabir authored Jul 31, 2024
2 parents 4e2137e + fdcb54b commit 738bd1c
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 182 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
[submodule "plugins/generic/crossref"]
path = plugins/generic/crossref
url = https://github.com/pkp/crossref-ojs
[submodule "plugins/generic/acron"]
path = plugins/generic/acron
url = https://github.com/pkp/acron
[submodule "plugins/generic/webFeed"]
path = plugins/generic/webFeed
url = https://github.com/pkp/webFeed.git
25 changes: 11 additions & 14 deletions classes/plugins/PubObjectsExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use APP\journal\Journal;
use APP\journal\JournalDAO;
use APP\notification\NotificationManager;
use APP\plugins\importexport\doaj\DOAJInfoSender;
use APP\submission\Submission;
use APP\template\TemplateManager;
use PKP\core\EntityDAO;
Expand All @@ -39,11 +40,13 @@
use PKP\plugins\Hook;
use PKP\plugins\importexport\PKPImportExportDeployment;
use PKP\plugins\ImportExportPlugin;
use PKP\plugins\interfaces\HasTaskScheduler;
use PKP\plugins\PluginRegistry;
use PKP\scheduledTask\PKPScheduler;
use PKP\submission\PKPSubmission;
use PKP\user\User;

abstract class PubObjectsExportPlugin extends ImportExportPlugin
abstract class PubObjectsExportPlugin extends ImportExportPlugin implements HasTaskScheduler
{
// The statuses
public const EXPORT_STATUS_ANY = '';
Expand Down Expand Up @@ -91,7 +94,6 @@ public function register($category, $path, $mainContextId = null)

$this->addLocaleData();

Hook::add('AcronPlugin::parseCronTab', [$this, 'callbackParseCronTab']);
foreach ($this->_getDAOs() as $dao) {
if ($dao instanceof SchemaDAO) {
Hook::add('Schema::get::' . $dao->schemaName, $this->addToSchema(...));
Expand Down Expand Up @@ -584,20 +586,15 @@ protected function _getObjectAdditionalSettings()
}

/**
* @copydoc AcronPlugin::parseCronTab()
* @copydoc \PKP\plugins\interfaces\HasTaskScheduler::registerSchedules()
*/
public function callbackParseCronTab($hookName, $args)
public function registerSchedules(PKPScheduler $scheduler): void
{
$taskFilesPath = &$args[0];

$scheduledTasksPath = "{$this->getPluginPath()}/scheduledTasks.xml";

if (!file_exists($scheduledTasksPath)) {
return false;
}

$taskFilesPath[] = $scheduledTasksPath;
return false;
$scheduler
->addSchedule(new DOAJInfoSender())
->everyMinute()
->name(DOAJInfoSender::class)
->withoutOverlapping();
}

/**
Expand Down
76 changes: 76 additions & 0 deletions classes/scheduler/Scheduler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* @file classes/scheduler/Scheduler.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class Scheduler
*
* @brief Core scheduler class, responsible to register scheduled tasks specific for the application
*/

namespace APP\scheduler;

use APP\tasks\OpenAccessNotification;
use APP\tasks\SubscriptionExpiryReminder;
use APP\tasks\UsageStatsLoader;
use PKP\scheduledTask\PKPScheduler;
use PKP\task\DepositDois;
use PKP\task\EditorialReminders;
use PKP\task\ReviewReminder;

class Scheduler extends PKPScheduler
{
/**
* @copydoc \PKP\scheduledTask\PKPScheduler::registerSchedules
*/
public function registerSchedules(): void
{
parent::registerSchedules();

$this
->schedule
->call(fn () => (new ReviewReminder())->execute())
->hourly()
->name(ReviewReminder::class)
->withoutOverlapping();

$this
->schedule
->call(fn () => (new DepositDois())->execute())
->hourly()
->name(DepositDois::class)
->withoutOverlapping();

$this
->schedule
->call(fn () => (new EditorialReminders())->execute())
->daily()
->name(EditorialReminders::class)
->withoutOverlapping();

$this
->schedule
->call(fn () => (new SubscriptionExpiryReminder())->execute())
->daily()
->name(SubscriptionExpiryReminder::class)
->withoutOverlapping();

$this
->schedule
->call(fn () => (new UsageStatsLoader([]))->execute())
->daily()
->name(UsageStatsLoader::class)
->withoutOverlapping();

$this
->schedule
->call(fn () => (new OpenAccessNotification())->execute())
->hourly()
->name(OpenAccessNotification::class)
->withoutOverlapping();
}
}
2 changes: 0 additions & 2 deletions classes/subscription/form/SubscriptionPolicyForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use APP\core\Application;
use APP\journal\JournalDAO;
use APP\template\TemplateManager;
use PKP\config\Config;
use PKP\db\DAORegistry;
use PKP\form\Form;

Expand Down Expand Up @@ -105,7 +104,6 @@ public function fetch($request, $template = null, $display = false)
'validNumWeeksBeforeExpiry' => $this->validNumWeeksBeforeExpiry,
'validNumMonthsAfterExpiry' => $this->validNumMonthsAfterExpiry,
'validNumWeeksAfterExpiry' => $this->validNumWeeksAfterExpiry,
'scheduledTasksEnabled' => (bool) Config::getVar('general', 'scheduled_tasks'),
'paymentsEnabled' => $paymentManager->isConfigured(),
]);

Expand Down
4 changes: 2 additions & 2 deletions classes/tasks/OpenAccessNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class OpenAccessNotification extends ScheduledTask
/**
* @copydoc ScheduledTask::getName()
*/
public function getName()
public function getName(): string
{
return __('admin.scheduledTask.openAccessNotification');
}
Expand Down Expand Up @@ -92,7 +92,7 @@ public function sendNotifications($journal, $curDate)
/**
* @copydoc ScheduledTask::executeActions()
*/
protected function executeActions()
protected function executeActions(): bool
{
$journalDao = DAORegistry::getDAO('JournalDAO'); /** @var JournalDAO $journalDao */
$journals = $journalDao->getAll(true);
Expand Down
5 changes: 3 additions & 2 deletions classes/tasks/SubscriptionExpiryReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SubscriptionExpiryReminder extends ScheduledTask
/**
* @copydoc ScheduledTask::getName()
*/
public function getName()
public function getName(): string
{
return __('admin.scheduledTask.subscriptionExpiryReminder');
}
Expand Down Expand Up @@ -235,7 +235,7 @@ protected function sendJournalReminders($journal, $curDate): void
/**
* @copydoc ScheduledTask::executeActions()
*/
protected function executeActions()
protected function executeActions(): bool
{
$journalDao = DAORegistry::getDAO('JournalDAO'); /** @var JournalDAO $journalDao */
$journals = $journalDao->getAll(true);
Expand Down Expand Up @@ -299,6 +299,7 @@ protected function executeActions()
}
}
}

return true;
}
}
39 changes: 34 additions & 5 deletions config.TEMPLATE.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
; To set the "Secure" attribute for the cookie see the setting force_ssl at the [security] group
session_samesite = Lax

; Enable support for running scheduled tasks
; Set this to On if you have set up the scheduled tasks script to
; execute periodically
scheduled_tasks = Off

; Site time zone
; Please refer to https://www.php.net/timezones for a full list of supported
; time zones.
Expand Down Expand Up @@ -575,6 +570,40 @@
; Remove this setting to leave failed jobs in the database.
delete_failed_jobs_after = 180

;;;;;;;;;;;;;;;;;;;;;;;;;;
; Schedule Task Settings ;
;;;;;;;;;;;;;;;;;;;;;;;;;;

[schedule]

; Whether or not to turn on the built-in schedule task runner
;
; When enabled, schedule tasks will be processed at the end of each web
; request to the application.
;
; Use of the built-in schedule task runner is highly discouraged for high-volume
; sites. Use your operational system's task scheduler instead, and configure
; it to run the task scheduler every minute.
; Sample for the *nix crontab
; * * * * * php lib/pkp/tools/scheduler.php run >> /dev/null 2>&1
;
; See: <link-to-documentation>
task_runner = On

; How often should the built-in schedule task runner run scheduled tasks at the
; end of web request life cycle (value defined in seconds).
;
; This configuration will only have effect for the build-it task runner, it doesn't apply
; to the system crontab configuration.
;
; The default value is set to 60 seconds, a value smaller than that might affect the
; application performance negatively.
task_runner_interval = 60

; When enabled, an email with the scheduled task result will be sent only when an error
; has occurred. Otherwise, all tasks will generate a notification.
scheduled_tasks_report_error_only = On

[invitations]
expiration_days = 3

Expand Down
1 change: 0 additions & 1 deletion dbscripts/xml/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<migration class="PKP\migration\install\InvitationsMigration" />
<migration class="PKP\migration\install\ReviewFormsMigration" />
<migration class="PKP\migration\install\SubmissionFilesMigration" />
<migration class="PKP\migration\install\ScheduledTasksMigration" />
<migration class="PKP\migration\install\LibraryFilesMigration" />
<migration class="PKP\migration\install\ReviewsMigration" />
<migration class="PKP\migration\install\TemporaryFilesMigration" />
Expand Down
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<migration class="PKP\migration\upgrade\v3_5_0\PreflightCheckMigration" fallback="3.4.9.9" />
<migration class="APP\migration\upgrade\v3_5_0\I8333_AddMissingForeignKeys" />
<migration class="PKP\migration\upgrade\v3_5_0\I9895_AddAppKeyToConfigFile"/>
<migration class="PKP\migration\upgrade\v3_5_0\I9678_RemoveScheduledTasksTable"/>
<migration class="PKP\migration\upgrade\v3_5_0\InstallEmailTemplates"/>
<migration class="PKP\migration\upgrade\v3_5_0\I9197_MigrateAccessKeys"/>
<migration class="PKP\migration\upgrade\v3_5_0\I9253_SiteAnnouncements"/>
Expand Down
6 changes: 6 additions & 0 deletions docs/release-notes/README-3.5.0
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ New config.inc.php parameters added for security:
- cipher (default value: ''), cipher algorithm used to generate app key and encryption purpose
- cookie_encryption (default value: ''), allow cookie encryption when set

New config.inc.php section for schedule task named schedule is added, with the following parameters:
- task_runner (default value: On), Whether or not to run the schedule tasks through web based task runner
- task_runner_interval (default value: 60), How often should the built-in web based task runner run scheduled tasks in seconds
- scheduled_tasks_report_error_only (default value: On), Whether or not schedule task execution failure details will be sent via mail

- The setting general.scheduled_tasks has been removed. It was supposed to control the schedule tasks but had no impact.

New Features
------------
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
9 changes: 0 additions & 9 deletions locale/en/manager.po
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,6 @@ msgstr "Review Options"
msgid "manager.setup.reviewOptions.automatedReminders"
msgstr "Automated Email Reminders"

msgid "manager.setup.reviewOptions.automatedRemindersDisabled"
msgstr "To send automated email reminders, the site administrator must enable the <tt>scheduled_tasks</tt> option in the OJS configuration file. Additional server configuration may be required as indicated in the OJS documentation."

msgid "manager.setup.reviewOptions.numWeeksPerReview"
msgstr "Weeks allowed to complete the review"

Expand Down Expand Up @@ -1074,9 +1071,6 @@ msgstr "Subscription Expiry Reminders"
msgid "manager.subscriptionPolicies.expiryRemindersDescription"
msgstr "Automated email reminders (available for editing by Journal Managers in OJS's Emails) can be sent to subscribers both before and after a subscription has expired."

msgid "manager.subscriptionPolicies.expiryRemindersDisabled"
msgstr "<strong>Note:</strong> To activate these options, the site administrator must enable the <tt>scheduled_tasks</tt> option in the OJS configuration file. Additional server configuration may be required to support this functionality (which may not be possible on all servers), as indicated in the OJS documentation."

msgid "manager.subscriptionPolicies.expirySelectOne"
msgstr "Select one of the following:"

Expand All @@ -1098,9 +1092,6 @@ msgstr "Please select a valid value for the number of weeks before subscription
msgid "manager.subscriptionPolicies.openAccessNotificationDescription"
msgstr "Registered readers will have the option of receiving the table of contents by email when an issue becomes open access."

msgid "manager.subscriptionPolicies.openAccessNotificationDisabled"
msgstr "<strong>Note:</strong> To activate this option, the site administrator must enable the <tt>scheduled_tasks</tt> option in the OJS configuration file. Additional server configuration may be required to support this functionality (which may not be possible on all servers), as indicated in the OJS documentation."

msgid "manager.subscriptionPolicies.onlinePaymentNotifications"
msgstr "Online Payment Notifications"

Expand Down
5 changes: 0 additions & 5 deletions pages/payments/PaymentsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use APP\subscription\form\PaymentTypesForm;
use APP\subscription\form\SubscriptionPolicyForm;
use APP\template\TemplateManager;
use PKP\config\Config;
use PKP\core\JSONMessage;
use PKP\core\PKPApplication;
use PKP\security\authorization\PKPSiteAccessPolicy;
Expand Down Expand Up @@ -142,10 +141,6 @@ public function subscriptionPolicies($args, $request)

$templateMgr = TemplateManager::getManager($request);

if (Config::getVar('general', 'scheduled_tasks')) {
$templateMgr->assign('scheduledTasksEnabled', true);
}

$paymentManager = Application::getPaymentManager($request->getJournal());
$templateMgr->assign('acceptSubscriptionPayments', $paymentManager->isConfigured());

Expand Down
1 change: 0 additions & 1 deletion plugins/generic/acron
Submodule acron deleted from cb707f
8 changes: 5 additions & 3 deletions plugins/importexport/doaj/DOAJInfoSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class DOAJInfoSender extends ScheduledTask
/**
* Constructor.
*/
public function __construct($args)
public function __construct(array $args = [])
{
PluginRegistry::loadCategory('importexport');

$plugin = PluginRegistry::getPlugin('importexport', 'DOAJExportPlugin'); /** @var DOAJExportPlugin $plugin */
$this->_plugin = $plugin;

Expand All @@ -44,15 +45,15 @@ public function __construct($args)
/**
* @copydoc ScheduledTask::getName()
*/
public function getName()
public function getName(): string
{
return __('plugins.importexport.doaj.senderTask.name');
}

/**
* @copydoc ScheduledTask::executeActions()
*/
public function executeActions()
public function executeActions(): bool
{
if (!$this->_plugin) {
return false;
Expand All @@ -71,6 +72,7 @@ public function executeActions()
$this->_registerObjects($unregisteredArticles, 'article=>doaj-json', $journal, 'articles');
}
}

return true;
}

Expand Down
Loading

0 comments on commit 738bd1c

Please sign in to comment.