Exemple #1
0
 public function testRegister()
 {
     $task = new ScheduledTask(array('task' => "something", 'schedule' => "daily"));
     preg_match("/X-App-Key: ([^']+)/", $task->getCommand(), $matches);
     $this->assertTrue(strlen($matches[1]) == 32, "should find a valid 32-char key.");
     $this->assertEquals($matches[1], Context::getAppKeys(AppKey::TYPE_SERVER)->first()->key, "tasks should use a valid server key");
 }
Exemple #2
0
 public function getCommand()
 {
     $shortcuts = array('hourly' => '0 * * * *', 'daily' => '0 0 * * *', 'monthly' => '0 0 1 * *', 'weekly' => '0 0 * * 0');
     $schedule = preg_match('/[a-z]/', $this->schedule) ? $shortcuts[$this->schedule] : $this->schedule;
     $protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
     // $public_url = $protocol . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['SCRIPT_NAME'] . '/' . $this->task;
     $public_url = $protocol . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '/' . $this->task;
     // retrieve server key to allow calls from crontab.
     $server_key = Context::getAppKeys(AppKey::TYPE_SERVER)->first();
     $curl_headers = "-H 'X-App-Id: {$server_key->app_id}' ";
     $curl_headers .= "-H 'X-App-Key: {$server_key->key}' ";
     $curl_headers .= "-H 'X-Scheduled-Task: yes' ";
     // Output the response to application log file
     $app = \Slim\Slim::getInstance();
     $output_file = $app->log->getWriter()->getFilePath();
     // Redirect stderr and stdout to file
     return $schedule . ' ' . "curl -XGET {$curl_headers} '{$public_url}' &> " . $output_file;
 }