R::wipe("job"); echo "The jobs have been wiped."; }); /** * @api {get} /api/v1/kill/:id Kills a job. * @apiDescription Kills a currently running job. * @apiGroup kill * @apiName KillJob * @apiVersion 1.0.0 * @apiExample {curl} Example usage: * curl 'http://pyro.demo/api/v1/kill/1 * @apiSuccess (200 OK) {String} A string indicating kill and delete were successful. * @apiError (400 Bad Request) {String) A string indicating the job does not exist. */ $app->get('/api/v1/kill/:id', function ($id) use($app) { $job = DB::GetJob($id); if ($job['id'] == 0) { echo 'The job does not exist'; } else { // For now we just straight up kill fds.exe // If we want to kill a specific job, we'll need to store what job is associated with what pid. shell_exec('taskkill /f /im fds.exe'); // Get the file it's in and remove everything except the .out file $directoryOfFile = 'uploads/' . $job['timestamp'] . '/*'; $files = glob($directoryOfFile); foreach ($files as $f) { if (substr($f, -4) !== ".out") { unlink($f); } } // Remove the job from the database.
public static function StopJob($id, $app) { $job = DB::GetJob($id); $filename = $job['name']; $timestamp = $job['timestamp']; $path = "uploads/" . $timestamp . '/' . substr($filename, 0, strlen($filename) - 4); $myfile = fopen($path . ".stop", "w"); $job->status = R::enum('status:Stopped'); R::store($job); $app->response(200); }