Pantheon Community

Cron Job Suggestions

I am used to being able to create my on cron job on the server using the crontab. So I have never used any of the Cron plugins or used cron jobs on the Pantheon platform before. I need to setup a cron job to run ever 10 seconds to make an API call and save response to a custom database table. I have it hooked up right now in my admin as a button, it takes around 1-3 seconds for the API call to finish and save the data to database. Our site traffic is usually around 30-50 during peak times and maybe 3-5 during off times. So probably never do not have at least one visitor on the site over any extended period of time. Does anyone have experience with dealing with cron jobs on WP without having the access to the server and setting up your own, using the crontab? What plugins would you suggest to use? Also, does WP Cron fire each time a person visits a page? if so, will this then kick off the cron job even thought is just ran? any suggestion or insights would be greatly appreciated!

Have you checked out this guide? https://pantheon.io/docs/wordpress-cron It has some good information about plugins and issues with cron jobs and high traffic sites.

yes, I did. I was hoping to find someone that has experience this before with some suggestions. I also just remembered that Cron only allows for a minimum of one minute. So this also might be a blocking issue. My overall thought was that saving this to the database would be a better faster experience for users than to have a direct API call on page load, then get the response, traverse the data to display on a Google Map. There is a lot going on, in this custom template, so I thought a quick DB call would be better since during peak time, there could be 20 or so users loading that page, thus each page load would be a call to that API. Plus this API has a limit of 10 second call internal. Again another possible blocking issue, why I went to saving the data to the custom database table instead of a call on each page load.

Thanks again!

So ideally you want near real time data, but are limited by the 10s rate limit. Is the data the same for all users?

Correct, right now I am experimenting with just using an Ajax call with a timer and scrap the whole cron job idea since Cron has its limitations also.

The data can be different or the same based on what the user chooses from a select element.
But once the API call is ran and saved, all the possible data options will be saved in the DB table
In other ideas?

That’s an interesting one and I’m not sure how I would handle that. Even having a small php script that you hit with an external cron would be a bad idea as it would generate about 260,000 additional page views a month!

thanks for the suggestions. So I have abandon the cron job idea. I have created an AJAX request with a timer to run the php function which makes the API call and saves the data to the database. So it is not based on pageload, nor is there an external cron generating extra page views.

Thanks jfoust for the discussion.