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"); }
public static function deploy($schedule) { // Don't proceed if there's nothing to schedule if (static::count() == 0 && count($schedule) == 0) { return false; } $cronfile = shared_storage_dir() . '/' . Context::getAppId() . '.cron'; $previous_tasks = file_exists($cronfile) ? file_get_contents($cronfile) : ""; $new_tasks = ''; // Remove all scheduled tasks for this app static::truncate(); foreach ($schedule as $task) { $task = ScheduledTask::create($task); $new_tasks .= $task->getCommand() . "\n"; } file_put_contents($cronfile, $new_tasks); static::install(); return $previous_tasks != $new_tasks; }
public function deploy() { set_time_limit(0); $statuses = array(); // application configs $configs = Input::get('config', array()); $configs['security'] = Input::get('security', array()); // Flush cache on deployment Cache\Cache::flush(); // Migrate and keep schema cache $collections_migrated = 0; foreach (Input::get('schema', array()) as $collection => $config) { if (Schema\Builder::getInstance()->migrate(Model\App::collection($collection)->getModel(), $config)) { $collections_migrated += 1; } } $statuses['schema'] = $collections_migrated; // do we have write permission on this server? if (is_writable(storage_dir())) { $statuses['config'] = Config::deploy($configs); $statuses['schedule'] = Model\ScheduledTask::deploy(Input::get('schedule', array())); // install composer packages $statuses['packages'] = Package\Manager::install(Input::get('packages', array())); } else { $error_message = array('error' => 'without write permissions'); $statuses['error'] = "Without write permissions. Ignoring 'config', 'schedule' and 'packages'."; } // modules $statuses['modules'] = Model\Module::deploy(Input::get('modules', array())); return $statuses; }