我正在尝试学习如何使用动作调度器,所以我希望能给我一些好的指导。我有以下代码:
<?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\' );
}
它似乎创建了操作,但从未运行。我尝试刷新网站的前端,但没有帮助。
有人能告诉我如何让它运行吗?
第二个问题是,这是否是分解一些繁重索引的正确方法,可能是使用参数,例如页面:“0-100”,页面:“101-200”,等等。
谢谢Dragos
SO网友:raftaar1191
require_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.org/usage/#scheduling-an-action