Unable to run custom CRON jobs on aws server
I am facing an issue with following code which is responsible to schedule a post to publish on some other website (developed in django). My code is able to publish the posts created in wordpress to django site from local server only (setup in docker image), but with same code snippet at AWS EC2 instance it fails to run the action defined in the scheduler. attaching a screenshot to understand all the default cron jobs are displaying to run in past.
my code in functions.php (it is ajax call)
add_action('wp_ajax_shedule', 'shedule');
add_action('wp_ajax_nopriv_shedule', 'shedule');
function shedule()
{
global $post;
$post_id = $_POST['post_id'];
$post_id = explode(_, $post_id);
$po = $post_id[0];
$time = $post_id[1];
$a = explode(T, $time);
$a = strtotime($a[0] . ' ' . $a[1] . 'Asia/Calcutta');
// echo $a; exit;
wp_schedule_single_event($a, 'Shedule_Post', array($po));
print_r(Post Schedule for . $time);
wp_die();
}
and scheduler action is:
add_action('Shedule_Post', 'Post_Shedule', 10);
function Post_Shedule($po)
{
// update_post_meta($po, test, 'hello');
global $post;
//fetch data from the below api
$api_url = site_url() . /wp-json/wl/v1/posts/$po/;
$result = file_get_contents($api_url); //stored in json format
//put data in the below mention api
$response = wp_remote_post(
'https://XXXXXXXXXXXXX.com/api/update_blog/',
array(
'method' = 'PUT',
'sslverify' = false,
'headers' = array(
'Content-Type' = 'application/json; charset=utf-8',
'Authorization' = 'Token XXXXXXXXXXXXXXXXXXXXXXXXXXX'
),
'body' = $result
)
);
}
please check the code snippet and suggest the possible action.
Topic scheduled-posts Wordpress
Category Web