Running a Script with Job Scheduler API I am trying to use the Job Scheduler Module's API to automatically run a script every 6 hours but I'm having problems getting it working.

This is the code:

function jobbank_cron_job_scheduler_info() {
  $schedulers = array();
  $schedulers['custom'] = array(
    'worker callback' =&gt; 'custom_job',
    'jobs' =&gt; array(
       array('crontab' =&gt; '6 * * * *', 'periodic' =&gt; TRUE),
    )
  );
  return $schedulers;
}


function get_job_bank() {
  //Save the (long) job bank URL
  $jobBankURL = "https://www.jobbank.gc.ca/xmllite/en/?q=city_id:33821";
  $jobURL = "https://www.jobbank.gc.ca/xmllite/en/";
  $jobs = [];
  $jobInfo = null;

  //Get the XML data into an object
  $jobsInfo = simplexml_load_file($jobBankURL);

  //Send a message and exit if it fails getting the XML
  if($jobsInfo === false) {
    mail ('webmastercolin@gmail.com',
          'Job Central SM Job Bank CRONjob issue',
          'Getting the $jobsInfo XML data failed (line 9) at '.date('H:i:s \o\n F j, Y'));
    exit();
  }

  //Iterate through the objects
  foreach($jobsInfo-&gt;Documents-&gt;Document as $job) {
    //Get the job data from Job Bank
    $jobInfo = simplexml_load_file($jobURL.$job-&gt;jobs_id.".xml");

    //Grab just the information for the job and put it in the array
    $jobs[] = $jobInfo-&gt;Documents-&gt;Document;
  }

  //Encode the array as JSON
  $json = json_encode($jobs);

  //Send a message and exit if it fails encoding the JSON
  if($json === false) {
    mail ('webmastercolin@gmail.com',
          'Job Central SM Job Bank CRONjob issue',
          'JSON encoding the array failed (line 23) at '.date('H:i:s \o\n F j, Y'));
    exit();
  }

  //Save new data to json file, overwriting existing
  $writeResult = file_put_contents($base_path . 'sites/default/files/jobbank/job-bank-data.json',$json,LOCK_EX);

  //Send a message and exit if overwriting the file failed
  if($writeResult === false) {
    mail ('webmastercolin@gmail.com',
          'Job Central SM Job Bank CRONjob issue',
          'Writing to the JSON file failed (line 31) at '.date('H:i:s \o\n F j, Y'));
    exit();
  }

  //Send a message on success, we are done
  mail ('webmastercolin@gmail.com',
        'Job Central SM Job Bank CRONjob Success!',
        'JSON creation succeeded at '.date('H:i:s \o\n F j, Y'));
  exit();
}


I appreciate the help.
If you want to schedule it every 6 hours, then it's 'crontab' =&gt; '0 /6 * * *'
The README.txt contains examples:



 /* Declare scheduler. */

  function example_cron_job_scheduler_info() {
    $schedulers = array();
    $schedulers['example_unpublish'] = array(
      'worker callback' =&gt; 'example_unpublish_nodes',
    );
    return $schedulers;
  }

 /* Add a job. */

  $job = array(
    'type' =&gt; 'story',
    'id' =&gt; 12,
    'crontab' =&gt; '0 /6 * * *', // I changed this line.
    'periodic' =&gt; TRUE,
  );
  JobScheduler::get('example_unpublish')-&gt;set($job);

 /* Work off a job. */

  function example_unpublish_nodes($job) {
    // Do stuff.
  }

 /* Remove a job. */

  $job = array(
    'type' =&gt; 'story',
    'id' =&gt; 12,
  );
  JobScheduler::get('example_unpublish')-&gt;remove($job);



'worker callback' =&gt; 'custom_job' it's bad practice to not include the name of your module in your callback. This is to prevent collisions. You should name it module_name_custom_callback. In your case it would be 'callback' =&gt; 'jobbank_custom_job'

The Job Scheduler is only going to schedule it, not run it. It will get run whenever cron runs. So if you have cron run set to once a day, it will only run your scheduled task once a day. Therefore, you will have to set cron to run every 6 hours or fewer.

Alternatively, I suggest you use a module like Ultimate   Cron which allows you to schedule different cron run times for different cron tasks. So you can set it to every 6 hours here.

This is the proper Drupal way to programmatically send e-mails How to programmatically send an email?