admin管理员组文章数量:1332873
I am trying to learn how to use the action scheduler so I am hoping somehow can give me some good pointers. I've got this code:
<?php
add_action( 'init', array( $this, 'wootomation_schedule' ) );
add_action( 'wootomation_import', array( $this, 'wootomation_do_action' ) );
function wootomation_schedule() {
// if ( false === as_next_scheduled_action( 'wootomation_import' ) ) {
// as_schedule_recurring_action( time(), 30, 'wootomation_import' );
// }
if ( false === as_next_scheduled_action( 'wootomation_import' ) ) {
as_enqueue_async_action( 'wootomation_import' );
}
}
function wootomation_do_action() {
var_dump('test');
wp_mail( '[email protected]', 'test AS', 'Action schedule completed' );
}
Which appears to create the action but it never runs. I tried refreshing the front end of the website but didn't help.
Can anyone tell me how to get it to run?
And the 2nd question would be, is this the right approach for breaking up some heavy indexing, maybe with args such as page: "0-100", page: "101-200", etc.
Thanks, Dragos
I am trying to learn how to use the action scheduler so I am hoping somehow can give me some good pointers. I've got this code:
<?php
add_action( 'init', array( $this, 'wootomation_schedule' ) );
add_action( 'wootomation_import', array( $this, 'wootomation_do_action' ) );
function wootomation_schedule() {
// if ( false === as_next_scheduled_action( 'wootomation_import' ) ) {
// as_schedule_recurring_action( time(), 30, 'wootomation_import' );
// }
if ( false === as_next_scheduled_action( 'wootomation_import' ) ) {
as_enqueue_async_action( 'wootomation_import' );
}
}
function wootomation_do_action() {
var_dump('test');
wp_mail( '[email protected]', 'test AS', 'Action schedule completed' );
}
Which appears to create the action but it never runs. I tried refreshing the front end of the website but didn't help.
Can anyone tell me how to get it to run?
And the 2nd question would be, is this the right approach for breaking up some heavy indexing, maybe with args such as page: "0-100", page: "101-200", etc.
Thanks, Dragos
Share Improve this question asked Jun 5, 2020 at 13:40 Dragos MicuDragos Micu 2132 silver badges9 bronze badges1 Answer
Reset to default 1require_once( plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php' );
/**
* Schedule an action with the hook 'eg_midnight_log' to run at midnight each day
* so that our callback is run then.
*/
function eg_log_action_data() {
if ( false === as_next_scheduled_action( 'eg_midnight_log' ) ) {
as_schedule_recurring_action( strtotime( 'midnight tonight' ), DAY_IN_SECONDS, 'eg_midnight_log' );
}
}
add_action( 'init', 'eg_log_action_data' );
/**
* A callback to run when the 'eg_midnight_log' scheduled action is run.
*/
function eg_log_action_data() {
error_log( 'It is just after midnight on ' . date( 'Y-m-d' ) );
}
add_action( 'eg_midnight_log', 'eg_log_action_data' );
Docs Link: https://actionscheduler/usage/#scheduling-an-action
本文标签: wp cronAction Scheduler not running
版权声明:本文标题:wp cron - Action Scheduler not running 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742311070a2450882.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论