Browse Source

Update 'api/cron.php'

master
pbug 8 years ago
parent
commit
0be2ac8f58
  1. 92
      api/cron.php

92
api/cron.php

@ -1,47 +1,47 @@
<?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 < ? 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"]."<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);
<?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);
}
Loading…
Cancel
Save