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.

46 lines
1.6 KiB

8 years ago
  1. <?php
  2. $pdo = new PDO('sqlite:db.sqlite3');
  3. $time = time();
  4. echo "Cronjob<br>";
  5. echo "Current time: ".$time."<br>";
  6. $query = $pdo->prepare('SELECT * FROM simulations WHERE timestamp+repeat_interval * repeat_count < ? AND (status="scheduled" OR status="repeating");');
  7. $query->execute(array($time));
  8. //if this has any rows, we got sims that should be started now.
  9. $sims = $query->fetchAll();
  10. foreach ($sims as $sim){
  11. $url = "192.168.76.210:19399/simengine/rest/launch";
  12. echo "Attempting to start simulation called ".$sim["sessionname"]."<br>";
  13. if ($sim["status"] == "scheduled")
  14. $query = $pdo->prepare("UPDATE simulations SET status = 'Done' WHERE id = ?");
  15. elseif($sim["status"] == "repeating")
  16. $query = $pdo->prepare("UPDATE simulations SET repeat_count = repeat_count+1 WHERE id = ?");
  17. $query->execute(array($sim["id"]));
  18. $headers = array("authorization: Basic ".$sim["token"],"Content-type: text/xml;charset=\"utf-8\"");
  19. var_dump($headers);
  20. echo "<br><br>";
  21. $content = $sim["topo_xml"];
  22. $url.="?session=".$sim["sessionname"];
  23. $ch = curl_init();
  24. curl_setopt($ch,CURLOPT_URL,$url);
  25. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  26. curl_setopt($ch,CURLOPT_HEADER, 0);
  27. curl_setopt($ch, CURLOPT_POSTFIELDS,$content);
  28. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  29. $output=curl_exec($ch);
  30. var_dump($output);
  31. $curlinfo = curl_getinfo ($ch);
  32. echo "<br><br>";
  33. var_dump($curlinfo);
  34. $response = json_decode($output,true);
  35. $return = array("response"=>$response,"httpinfo"=>$curlinfo);
  36. curl_close($ch);
  37. }