Skip to content

Commit

Permalink
Add Action Scheduler controller to keep track of AS tasks via `PRONAM…
Browse files Browse the repository at this point in the history
…IC_ACTION_SCHEDULER_CONTEXT` define.
  • Loading branch information
remcotolsma committed Jan 22, 2024
1 parent af402e0 commit b1c28b0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/ActionSchedulerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Action Scheduler Controller
*
* @author Pronamic <info@pronamic.eu>
* @copyright 2005-2023 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\Pay
*/

namespace Pronamic\WordPress\Pay;

/**
* Action Scheduler Controller class
*/
class ActionSchedulerController {
/**
* Setup.
*
* @return void
*/
public function setup() {
\add_action( 'action_scheduler_begin_execute', [ $this, 'begin_execute' ], 10, 2 );
}

/**
* Action scheduler begin execute.
*
* @link https://github.com/woocommerce/action-scheduler/blob/3.7.1/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php#L84
* @param int $action_id Action ID.
* @param string $context Context.
* @return void
*/
public function begin_execute( $action_id, $context ) {
if ( \defined( 'PRONAMIC_ACTION_SCHEDULER_CONTEXT' ) ) {
return;
}

\define( 'PRONAMIC_ACTION_SCHEDULER_CONTEXT', $context );
}
}
1 change: 1 addition & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ public function plugins_loaded() {
$controllers = [
new PagesController(),
new HomeUrlController(),
new ActionSchedulerController(),
];

foreach ( $controllers as $controller ) {
Expand Down

0 comments on commit b1c28b0

Please sign in to comment.