Hello,
Is the first time I post here. I am a front end developer, I have successfully learned the process and I have already used Trellis/Bedrock/Sage for three projects already and I am extremely happy!
Unfortunately I am not an expert and I really want to learn more but there is something that I need to do for a project and I don’t know how to do it.
I am using a plugin that import data from an xml file uploaded somewhere. In the docs they mention that you can setup a cron job using two urls (one is a trigger URL and one a processing URL)
The trigger URL will look something like this:
http://YOUR-WEBSITE.com/wp-cron.php?import_key=[YOUR_SECRET_KEY]&import_id=[YOUR_IMPORT_ID]&action=trigger
The processing URL will look something like this:
http://YOUR-WEBSITE.com/wp-cron.php?import_key=[YOUR_SECRET_KEY]&import_id=[YOUR_IMPORT_ID]&action=processing
I have read a lot on WP_CRON on Trellis, I know is disabled and that there is a “Setup WP system cron” task, and I tried to make my own using the wget command. But I am not able to do it and I was wondering if someone could help me figure this out. I don’t know if I can link the plugin docs here, If I am allowed I will do so.
Can someone guide me on how to create this custom cron jobs to run with the given URLs?
Thanks in advance
- name: Plugin cron
cron:
name: "{{ item.key }} Plugin cron"
minute: "*/15"
user: "{{ web_user }}"
job: "curl http://your-website.com/wp-cron.php?import_key=%5BYOUR_SECRET_KEY%5D&import_id=%5BYOUR_IMPORT_ID%5D&action=trigger"
cron_file: "plugin-name-cron"
with_dict: "{{ wordpress_sites }}"
when: item.key == "key of site"
You’d want to add a cron
task like this somewhere. You could create another role for it.
This isn’t 100% ideal, but you can only add it for the site you want by replacing by "key of site"
. Or just skip with_dict
and hardcode it:
- name: Plugin cron
cron:
name: "Plugin cron"
minute: "*/15"
user: "{{ web_user }}"
job: "curl http://your-website.com/wp-cron.php?import_key=%5BYOUR_SECRET_KEY%5D&import_id=%5BYOUR_IMPORT_ID%5D&action=trigger"
cron_file: "plugin-name-cron"
2 Likes
Hi.
Thanks a lot for your help. I can see from the syslog that it indeed works
Mar 28 17:42:01 nucreativetalent-staging CRON[13386]: (web) CMD (curl http://talent.nucreativetesting.co.uk/wp-cron.php?import_key=p41IqrDqm&import_id=1&action=trigger)
Mar 28 17:42:01 nucreativetalent-staging CRON[13387]: (web) CMD (curl http://talent.nucreativetesting.co.uk/wp-cron.php?import_key=p41IqrDqm&import_id=1&action=processing)
although nothing happens on the website unfortunately.
In their documentation they use wget -q -O /dev/null “URL” so they put the URL in quotes and they use wget. I don’t get the /dev/null, I will probably ask the support.
Can I just ask what the cron_file: "plugin-name-cron"
does?
Thanks a lot for your help 
cron_file: "plugin-name-cron"
means Ansible will create a cron file with that name instead of just adding an entry to the “global” cron tab. Just organizes it a little better.
1 Like
Hello
I figured it out why it wasn’t working!
Of course trellis changes the default WordPress structure adding wp in the slug, so the url should be wp/wp-cron.php
job: "curl http://your-website.com/wp/wp-cron.php?import_key=%5BYOUR_SECRET_KEY%5D&import_id=%5BYOUR_IMPORT_ID%5D&action=trigger
Hope this can help
Easy to miss when you are used to the default WordPress structure!
Just one last question: is there a way for me to change the hardcoded URL in the job? I would like to take it the canonical url depending on the environment of course.
Thanks
2 Likes