You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
$pdo = new PDO('sqlite:db.sqlite3'); $time = time(); echo "Cronjob<br>"; echo "Current time: ".$time."<br>";
$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"]."<br>"; 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 "<br><br>"; $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 "<br><br>"; var_dump($curlinfo); $response = json_decode($output,true); $return = array("response"=>$response,"httpinfo"=>$curlinfo); curl_close($ch); }
|