diff --git a/api/cron.php b/api/cron.php index e6c5cef..598da94 100644 --- a/api/cron.php +++ b/api/cron.php @@ -1,47 +1,47 @@ -"; -echo "Current time: ".$time."
"; - -$query = $pdo->prepare('SELECT * FROM simulations WHERE timestamp+repeat_interval * repeat_count < ? AND (status="scheduled" OR status="repeating");'); -$query->execute(array($time)); - -//if this has any rows, we got sims that should be started now. -$sims = $query->fetchAll(); - - - -foreach ($sims as $sim){ - $url = "192.168.76.210:19399/simengine/rest/launch"; - echo "Attempting to start simulation called ".$sim["sessionname"]."
"; - if ($sim["status"] == "scheduled") - $query = $pdo->prepare("UPDATE simulations SET status = 'Done' WHERE id = ?"); - elseif($sim["status"] == "repeating") - $query = $pdo->prepare("UPDATE simulations SET repeat_count = repeat_count+1 WHERE id = ?"); - - - $query->execute(array($sim["id"])); - - $headers = array("authorization: Basic ".$sim["token"],"Content-type: text/xml;charset=\"utf-8\""); - var_dump($headers); - echo "

"; - $content = $sim["topo_xml"]; - $url.="?session=".$sim["sessionname"]; - $ch = curl_init(); - curl_setopt($ch,CURLOPT_URL,$url); - curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); - curl_setopt($ch,CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_POSTFIELDS,$content); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - $output=curl_exec($ch); - var_dump($output); - $curlinfo = curl_getinfo ($ch); - echo "

"; - var_dump($curlinfo); - $response = json_decode($output,true); - $return = array("response"=>$response,"httpinfo"=>$curlinfo); - - curl_close($ch); +"; +echo "Current time: ".$time."
"; + +$query = $pdo->prepare('SELECT * FROM simulations WHERE timestamp+repeat_interval * repeat_count < '.$time.' AND (status="scheduled" OR status="repeating");'); +$query->execute(); + +//if this has any rows, we got sims that should be started now. +$sims = $query->fetchAll(); + + + +foreach ($sims as $sim){ + $url = "192.168.76.210:19399/simengine/rest/launch"; + echo "Attempting to start simulation called ".$sim["sessionname"]."
"; + if ($sim["status"] == "scheduled") + $query = $pdo->prepare("UPDATE simulations SET status = 'Done' WHERE id = ?"); + elseif($sim["status"] == "repeating") + $query = $pdo->prepare("UPDATE simulations SET repeat_count = repeat_count+1 WHERE id = ?"); + + + $query->execute(array($sim["id"])); + + $headers = array("authorization: Basic ".$sim["token"],"Content-type: text/xml;charset=\"utf-8\""); + var_dump($headers); + echo "

"; + $content = $sim["topo_xml"]; + $url.="?session=".$sim["sessionname"]; + $ch = curl_init(); + curl_setopt($ch,CURLOPT_URL,$url); + curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); + curl_setopt($ch,CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_POSTFIELDS,$content); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + $output=curl_exec($ch); + var_dump($output); + $curlinfo = curl_getinfo ($ch); + echo "

"; + var_dump($curlinfo); + $response = json_decode($output,true); + $return = array("response"=>$response,"httpinfo"=>$curlinfo); + + curl_close($ch); } \ No newline at end of file