/** * Camelizes string * * @param string $input * @return string Returns camelized string */ public function camelize($input) { return \Scalr::camelize($input); }
set_time_limit(0); $opt = getopt('', ['name:']); //10 KiB of emergency memory Scalr::$emergencyMemory = str_repeat(' ', 10240); if (empty($opt['name']) || !preg_match('/^[\\w]+(\\.|$)/', $opt['name'])) { printf("Usage: worker.php --name=service [options]\n"); exit; } //Service name is expected $service = $opt['name']; //The name of the service might be composite (scalarizr_messaging.HostInit.655) if (($dot = strpos($service, '.')) !== false) { $cls = \Scalr::camelize(substr($service, 0, $dot)); } else { //name of the class in camel case $cls = \Scalr::camelize($service); } //Checking if task class exists. if (!file_exists(SRCPATH . '/Scalr/System/Zmq/Cron/Task/' . $cls . '.php')) { printf("Launch error. File %s does not exist.\n", SRCPATH . '/Scalr/System/Zmq/Cron/Task/' . $cls . '.php'); exit; } $taskClass = 'Scalr\\System\\Zmq\\Cron\\Task\\' . $cls; /* @var $task \Scalr\System\Zmq\Cron\AbstractTask */ $task = new $taskClass(); $config = $task->config(); //Initializes MDP Worker $worker = (new Worker(Scalr::config('scalr.crontab.sockets.broker'), $service, true))->setHeartbeat(Scalr::config('scalr.crontab.heartbeat.delay'))->setLiveness(Scalr::config('scalr.crontab.heartbeat.liveness'))->setLogger(\Scalr::getContainer()->logger('cron/worker.php')->setLevel(\Scalr::config('scalr.crontab.log_level')))->connect(); $interrupt = 0; // Whether the worker lost connection to the broker. $disconnected = false;
/** * Gets server history object * * @return \Scalr\Server\History Returns server history object */ public function getServerHistory() { $bSave = false; $mapping = array('envId' => 'envId', 'farmId' => 'farmId', 'farmRoleid' => 'farmRoleId', 'serverIndex' => 'index', 'cloudLocation' => 'cloudLocation'); if (!isset($this->serverHistory)) { $this->serverHistory = new \Scalr\Server\History(); $info = $this->Db->GetRow("\n SELECT * FROM servers_history WHERE server_id = ? LIMIT 1\n ", array($this->serverId)); if (!$info) { $this->serverHistory->clientId = $this->clientId; $this->serverHistory->serverId = $this->serverId; $this->serverHistory->platform = $this->platform; $this->serverHistory->cloudLocation = $this->cloudLocation; foreach ($mapping as $prop => $key) { $this->serverHistory->{$prop} = $this->{$key}; } $bSave = true; } else { foreach ($info as $key => $value) { $prop = lcfirst(\Scalr::camelize($key)); $this->serverHistory->{$prop} = $value; if (array_key_exists($prop, $mapping)) { if ($value != $this->{$mapping[$prop]}) { $this->serverHistory->{$prop} = $this->{$mapping[$prop]}; $bSave = true; } } } } if (!$this->serverHistory->cloudServerId) { $this->serverHistory->cloudServerId = $this->GetCloudServerID(); $this->serverHistory->type = $this->GetFlavor(); $bSave = true; } } else { foreach ($mapping as $prop => $key) { if ($this->serverHistory->{$prop} != $this->{$key}) { $this->serverHistory->{$prop} = $this->{$key}; $bSave = true; } } } if (!empty($bSave)) { $this->serverHistory->save(); } return $this->serverHistory; }