Sync Blueprint courses via API

Jump to solution
nschutz
Community Contributor

Recently we made a across the board change to all the blueprint courses and therefore need to trigger the unsynced changes so the associated courses get updated as well. The API is provided to do that and I tested it successfully in Postman, updating 1 course at a time.

POST /api/v1/courses/:course_id/blueprint_templates/:template_id/migrations

However, when I have to run this for all the blueprint courses, it only executed a few courses at a time as if there were a limit enforced somewhere. I increased the timeout value from 30 to 600 and still only the same number of courses were synced. Does anyone know where the limit comes from? How to increase it? or how to work around this so I can run the script once for all the 100+ blueprint courses?

Below is my PHP code snippet.

<?php
// this page will run force sync on the supplied blueprint courses.
$courseIDs = array(xxx, xxx, xxx); //the array contains over 100 course ids
$length = count($courseIDs);
for($i = 0; $i < $length; ++$i) {
    $cid = $courseIDs[$i];
    $postURL = "domainurl" . $cid . "/blueprint_templates/default/migrations";
    $curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => $postURL,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 600, //increased from 30
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer xxxxx
        "Cache-Control: no-cache",
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

}
?>

Labels (1)
0 Likes
1 Solution
nschutz
Community Contributor

I figured out why only the first few requests were processed. It was a default setting in the php.ini file of max_execution_time=30, which limits the running time of the script to 30 seconds. I changed that value and restarted my server and all requests went through.

View solution in original post