Serveral custom cron jobs in Trellis/Bedrock stack

Hi, I’m trying to create two different cron jobs for WP All Import. I’m not really sure how to add these cron jobs and make them run. I’ve created a task in main.yml (roles/wordpress-setup/tasks) as well as in wordpress_sites.yml where the job is defined.

Is it possible to have several jobs or should I somehow add my tasks to systemcron?

Thank you

If you’re looking to setup system crons you’ll want to use http://docs.ansible.com/ansible/latest/cron_module.html

You can see an example in Trellis for the WP cron that is setup: https://github.com/roots/trellis/blob/e0fee339fd72123b7e7accab4a2367de895995a1/roles/wordpress-setup/tasks/main.yml#L45-L53

1 Like

Hi Ben!

I’m working in the same theme team as @Olle_Linderos and I have som further questions about custom cron tasks.

The following code is defined in roles/wordpress-setup/tasks/main.yml as a task:

    - name: WP All Import cron
       cron:
          name: "{{ item.key }} - WP All Import cron"
          hour: "{{ item.value.cron.hour | default('*') }}"
          minute: "{{ item.value.cron.minute | default('*') }}"
          user: "{{ web_user }}"
          job: "cd {{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }} && {{        item.value.cron.job }} > /dev/null 2>&1"
         cron_file: "wp-all-import-cron"
      with_dict: "{{ wordpress_sites }}"
      when: item.value.cron | default(false)

Then I have specified the following in group_vars/environment/wordpress-sites.yml

cron:
  job: "curl http://your-website.com/wp-cron.php?import_key=%5BYOUR_SECRET_KEY%5D&import_id=%5BYOUR_IMPORT_ID%5D&action=trigger"
  hour: "3"
  minute: "0"
system_cron: true

Are we on the right track or would you recommend any other solution. Remember, we will run 4 unique wp cron urls. 2 per import profile, one trigger and one processing. And of course, it’s important for us to have different links for different environments.

Try adding /wp/ to your curl path, as Bedrock changes the path of wp-cron.php:

cron:
  job: "curl http://your-website.com/wp/wp-cron.php?import_key=%5BYOUR_SECRET_KEY%5D&import_id=%5BYOUR_IMPORT_ID%5D&action=trigger"
  hour: "3"
  minute: "0"
system_cron: true