action-scheduler
action-scheduler copied to clipboard
Marked as failed process keeps running.
I am trying to import a lot of products into the WooCommerce database, however I have a hard time using this library.
I am using the library as such:
define('EXE_TIME', 0);
/**
* REGISTER
*/
register_activation_hook(__FILE__, 'interdeco_plugin_activation');
function interdeco_plugin_activation()
{
if (!as_has_scheduled_action('interdeco_sync_all')) {
as_schedule_cron_action( strtotime('01:00:00'), '0 1,11,16 * * *', 'interdeco_sync_all' );
}
}
/**
* UNREGISTER
*/
register_deactivation_hook(__FILE__, 'interdeco_plugin_deactivation');
function interdeco_plugin_deactivation()
{
as_unschedule_action('interdeco_sync_all');
}
/**
* SYNC HOOKS
*/
add_action('interdeco_sync_stock', function () {
inter_log('Started.');
ProductSync(true);
inter_log('Ended.');
});
add_action('interdeco_sync_all', function () {
inter_log('Started.');
ProductSync(false);
inter_log('Ended.');
});
/**
* UTILS
*/
add_filter('action_scheduler_queue_runner_time_limit', 'eg_increase_time_limit', 10, 1);
function eg_increase_time_limit($time_limit)
{
$time_limit = EXE_TIME;
return $time_limit;
}
The ProductSync method downloads an xml and accroding uploads the pictures and product details.
In the admin panel this error message pops up, yet I see images being downloaded.
2022-07-27 12:17:25 +0000
action marked as failed after 0 seconds. Unknown error occurred. Check server, PHP and database error logs to diagnose cause.
I have tried to check wp debug.log, apache error.log but nothing indicates the error.
Also, how can I keep the cron job, even if it fails? (Change its status back to pending.)
There's not quite enough information here for us to help.
However, I'd note that if I take the code you shared and set it up in a brand new plugin, alongside two 'stub' functions:
function inter_log() {}
function ProductSync() {}
Things work correctly. I see the new pending action and if I run it manually, it completes successfully. This indicates the issue may lie somewhere in the 'real' implementations of the above two functions, and so may not be an issue in Action Scheduler itself.
If you replicate my test using the same simplification, do you see the same?