Skip to content
This repository was archived by the owner on May 2, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions includes/WpMinions/Cron/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,31 @@ public function register() {
*/
public function add( $hook, $args = array(), $priority = 'normal' ) {
// Priority isn't really something we can manage with wp-cron
wp_schedule_single_event( time(), $hook, $args );
$job_data = array(
'hook' => $hook,
'args' => $args,
'blog_id' => get_current_blog_id(),
);

$job_data = apply_filters( 'wp_async_task_add_job_data', $job_data );

if ( function_exists( 'is_multisite' ) && is_multisite() && $job_data['blog_id'] ) {
$blog_id = $job_data['blog_id'];

if ( get_current_blog_id() !== $blog_id ) {
switch_to_blog( $blog_id );
$switched = true;
} else {
$switched = false;
}
}

wp_schedule_single_event( time(), $job_data['hook'], $job_data['args'] );

if ( $switched ) {
restore_current_blog();
}

return true;
}

}
8 changes: 5 additions & 3 deletions includes/WpMinions/Gearman/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function register() {

if ( ! defined( 'PHPUNIT_RUNNER' ) ) {
error_log( "Fatal Gearman Error: Failed to register servers ($servers)" );
error_log( " Cause: " . $e->getMessage() );
error_log( ' Cause: ' . $e->getMessage() );
}

return false;
Expand All @@ -70,6 +70,8 @@ public function add( $hook, $args = array(), $priority = 'normal' ) {
'blog_id' => $this->get_blog_id(),
);

$job_data = apply_filters( 'wp_async_task_add_job_data', $job_data );

$client = $this->get_gearman_client();

if ( $client !== false ) {
Expand All @@ -80,6 +82,7 @@ public function add( $hook, $args = array(), $priority = 'normal' ) {

return call_user_func( $callable, $group, $payload );
} else {
error_log( 'Client fail' );
return false;
}
}
Expand All @@ -93,7 +96,7 @@ public function add( $hook, $args = array(), $priority = 'normal' ) {
* @return string The corresponding method name
*/
function get_background_method( $priority ) {
switch( strtolower( $priority ) ) {
switch ( strtolower( $priority ) ) {
case 'high':
$method = 'doHighBackground';
break;
Expand Down Expand Up @@ -178,5 +181,4 @@ function get_gearman_client() {
function get_blog_id() {
return function_exists( 'is_multisite' ) && is_multisite() ? get_current_blog_id() : false;
}

}
2 changes: 1 addition & 1 deletion includes/WpMinions/Gearman/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function register() {

if ( ! defined( 'PHPUNIT_RUNNER' ) ) {
error_log( "Fatal Gearman Error: Failed to register servers ($servers)" );
error_log( " Cause: " . $e->getMessage() );
error_log( ' Cause: ' . $e->getMessage() );
}

return false;
Expand Down
3 changes: 1 addition & 2 deletions includes/WpMinions/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function quit( $status_code ) {
* @return string Path to the wp-load.php file
*/
function get_wp_load() {
$wp_dir = dirname( $_SERVER['SCRIPT_FILENAME'] ) ;
$wp_dir = dirname( $_SERVER['SCRIPT_FILENAME'] );
return $wp_dir . '/wp-load.php';
}

Expand All @@ -338,5 +338,4 @@ function load_wordpress() {
return $this->quit( 1 );
}
}

}
4 changes: 3 additions & 1 deletion includes/WpMinions/RabbitMQ/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ public function add( $hook, $args = array(), $priority = 'normal' ) {
'blog_id' => get_current_blog_id(),
);

$job_data = apply_filters( 'wp_async_task_add_job_data', $job_data );

$message = new \PhpAmqpLib\Message\AMQPMessage(
json_encode( $job_data ) );
json_encode( $job_data ) );

$this->connection->get_channel()->basic_publish( $message, '', 'wordpress' );
}
Expand Down