/** * Start a worker */ protected function _startWorker() { $worker = new Worker(); $worker->logLevel = $this->logLevel; fwrite(STDOUT, '*** Starting scheduler worker ' . PHP_EOL); $worker->work($this->interval); }
/** * Adds a worker to the action. * * @param Worker $worker * * @return Action * @throws \Exception */ public function addWorker($worker) { if (!$worker instanceof Worker) { throw new \Exception('$worker is not an instance of Worker'); } $this->workerList[$worker->getId()] = $worker; return $this; }
public function testGetStacked() { $worker = new Worker(); $work = new WorkerTestWork(); $worker->stack($work); $this->assertEquals(1, $worker->getStacked()); $worker->stack($work); $this->assertEquals(2, $worker->getStacked()); }
/** * When the timeout passed to ::processOne() is 0 and there are no jobs it should return quitely. * @throws Exception\WorkerException */ public function testWorkerNoJobs() { $testWorkerRuns = $this; $tube = 'worker_tube_' . rand(53, 504); $data = 'worker_value_' . rand(95, 3000); $pheanstalk = new Pheanstalk(self::SERVER_HOST, self::SERVER_PORT); $worker = new Worker(self::SERVER_HOST, self::SERVER_PORT); $worker->register($tube, function (Job $job) use($testWorkerRuns, $data) { $testWorkerRuns->assertEquals($data, $job->getData()); }); $processedJob = $worker->processOne(0); $stats = $pheanstalk->statsTube($tube); $this->assertEquals($stats['total-jobs'], 0); }
private function startWorkers() { $wrapper = realpath(__DIR__ . '/../../../../bin/phpunit-wrapper'); for ($i = 1; $i <= $this->options->processes; $i++) { $worker = new Worker(); if ($this->options->noTestTokens) { $token = null; } else { $token = $i; } $worker->start($wrapper, $token); $this->streams[] = $worker->stdout(); $this->workers[] = $worker; } }
public function start($options = PTHREADS_INHERIT_ALL) { ThreadManager::getInstance()->add($this); if (!$this->isRunning() and !$this->isJoined() and !$this->isTerminated() and !$this->isShutdown()) { return parent::start($options); } return false; }
function __construct($config) { parent::__construct($config); $this->register_handler("do_get_testsyncphp_thing_v1"); $this->register_handler("do_put_testsyncphp_thing_v1"); $this->register_handler("do_post_testsyncphp_thing_v1"); $this->register_handler("do_delete_testsyncphp_thing_v1"); }
protected function release() { if (count($this->sqlArray) > 0) { $this->executeSql(); } parent::release(); // TODO: Change the autogenerated stub }
function __construct($config) { parent::__construct($config); $this->register_handler("do_get_barn_animal_v1"); $this->register_handler("do_put_barn_animal_v1"); $this->register_handler("do_post_barn_animal_v1"); $this->register_handler("do_delete_barn_animal_v1"); }
function __construct($config) { parent::__construct($config); $this->register_handler("do_get_testdelayphp_counter_v1"); $this->register_handler("do_post_testdelayphp_counter_v1"); $this->register_handler("do_delete_testdelayphp_counter_v1"); $this->register_handler("do_increment_testdelayphp_counter_v1"); }
public function testWorkerGc() { $worker = new Worker(); $work = new WorkerTestWork(); $worker->start(); $worker->stack($work); $work->synchronized(function ($work) { if (!$work->isGarbage()) { $work->wait(); } }, $work); $this->assertEquals($worker->collect(function ($task) { return false; }), 1); $this->assertEquals($worker->collect(function ($task) { return $task->isGarbage(); }), 0); }
function __construct($config) { parent::__construct($config); $this->register_handler("do_post_testcancelphp_thing_v1"); $this->register_handler("do_cancel_testcancelphp_thing_v1"); $this->register_handler("do_post_testcancelphp_continuation_v1"); $this->register_handler("do_run_testcancelphp_continuation_v1"); $this->register_handler("do_finish_testcancelphp_continuation_v1"); }
{ echo $user->getUsername(); } public function server() { $ws_worker = new \Worker("websocket://0.0.0.0:2346"); $ws_worker->count = 4; $ws_worker->onMessage = function ($connection, $data) { $connection->send('hello ' . $data); };
public function start(int $options = PTHREADS_INHERIT_ALL) { ThreadManager::getInstance()->add($this); if (!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()) { if ($this->getClassLoader() === null) { $this->setClassLoader(); } return parent::start($options); } return false; }
function __construct($config) { parent::__construct($config); $this->register_handler("do_get_testagentsphp_thing_v1", "thing_handler"); $this->register_handler("do_post_testagentsphp_thing_v1", "thing_handler"); $this->register_handler("do_delete_testagentsphp_thing_v1", "thing_handler"); foreach (array("A", "B", "C", "D") as $resource) { foreach (array("reg", "unreg") as $op) { $this->register_handler("do_{$op}_testagentsphp_{$resource}_v1", "dummy_handler"); } } }
/** * Save or update worker * @param Worker $worker * @return Worker */ public function saveWorker(Worker $worker) { if (is_null($worker->getId())) { $query = $this->db->prepare("INSERT INTO workers (host, port, type, status) VALUES (?, ?, ?, ?)"); $query->execute([$worker->getHost(), $worker->getPort(), $worker->getType(), $worker->getStatus()]); $worker->setId($this->db->lastInsertId()); } else { $query = $this->db->prepare("UPDATE workers SET host = ?, port = ?, type = ?, status = ? WHERE id = ?"); $query->execute([$worker->getHost(), $worker->getPort(), $worker->getType(), $worker->getStatus(), $worker->getId()]); } return $worker; }
public function fillData(ShiftAssignmentView $shiftassignment) { $this->workerid = $shiftassignment->workerid; $this->stationid = $shiftassignment->stationid; $this->expoid = $shiftassignment->expoid; $this->expo = $shiftassignment->expoTitle; $this->station = $shiftassignment->location . " (" . $shiftassignment->stationTitle . ")"; $this->startTime = $shiftassignment->startTime; $this->stopTime = $shiftassignment->stopTime; $worker = Worker::selectID($shiftassignment->workerid); $this->workerName = $worker->nameString2(); $this->workerEmail = $worker->email; return $this; }
function createShiftCheckInHTMLList($expoid, $stationid) { echo "<div id=\"workerlist_table\">\n"; echo "<form method=\"POST\" name=\"ShiftCheckIn_form\" action=\"ShiftCheckInAction.php?" . PARAM_LIST_INDEX . "=" . $stationid . "\">\n"; echo "<table>\n"; $shiftAssignmentList = ShiftAssignmentView::selectStation($expoid, $stationid); $c = count($shiftAssignmentList); $workerList = array(); for ($k = 0; $k < $c; $k++) { $workerList[$k] = Worker::selectID($shiftAssignmentList[$k]->workerid); } usort($workerList, "WorkerCompare"); echo "<tr><td class=\"rowTitle\" colspan=\"4\">Supervisors</td></tr>\n"; $supervisors = 0; for ($k = 0; $k < $c; $k++) { if ($workerList[$k]->isSupervisor() && !$workerList[$k]->isDisabled) { $ss = ShiftStatus::mostRecentStatus($workerList[$k]->workerid, $stationid, $expoid); if (count($ss) > 0) { $statusType = $ss->statusType; } else { $statusType = NULL; } makeShiftCheckInListHTMLRows($workerList[$k], $statusType); $supervisors++; } } if ($supervisors == 0) { echo "<tr><td class=\"fieldError\" colspan=\"4\">There are currently no Supervisors assigned to this station.</td></tr>\n"; } echo "<tr><td class=\"rowTitle\" colspan=\"4\">Crew</td></tr>\n"; $crew = 0; for ($k = 0; $k < $c; $k++) { if ($workerList[$k]->isCrewMember() && !$workerList[$k]->isDisabled) { $ss = ShiftStatus::mostRecentStatus($workerList[$k]->workerid, $stationid, $expoid); if (count($ss) > 0) { $statusType = $ss->statusType; } else { $statusType = NULL; } makeShiftCheckInListHTMLRows($workerList[$k], $statusType); $crew++; } } // $k if ($crew == 0) { echo "<tr><td class=\"fieldError\" colspan=\"4\">There are currently no Crew assigned to this station.</td></tr>\n"; } echo "</table></form></div><!-- workerlist_table -->\n"; }
/** * Show the form for creating a new resource. * @param Request $request * @return Response */ public function postRelated(Request $request) { $people = People::all(); $worker = Worker::all(); $ids = array(); for ($i = 0; $i < $worker->count(); $i++) { for ($j = 0; $j < $people->count(); $j++) { if ($people->get($j)->id == $worker->get($i)->people_id) { $ids[] = $people->get($j)->id; } } } $people = People::whereNotIn('id', $ids)->get(); $branch = Branch::findOrFail($request->get('id')); return view('admin.listpeople', compact('people', 'branch')); }
function __construct($config) { parent::__construct($config); $this->register_handler("do_get_testchainedphp_hello_v1"); $this->register_handler("do_get_internalphp_hello1_v1"); $this->register_handler("do_post_testchainedphp_hello2_v1"); $this->register_handler("do_get_testchainedphp_goodbye_v1"); $this->register_handler("do_post_testchainedphp_goodbye_v1"); $this->register_handler("do_append_internalphp_goodbye1_v1"); $this->register_handler("do_append_internalphp_goodbye2_v1"); $this->register_handler("do_get_testchainedphp_thing_v1"); $this->register_handler("do_post_testchainedphp_thing_v1"); $this->register_handler("do_reg_internalphp_service1_v1"); $this->register_handler("do_post_testchainedphp_service2_v1"); $this->register_handler("do_delete_testchainedphp_thing_v1"); $this->register_handler("do_unreg_internalphp_service1_v1"); $this->register_handler("do_delete_testchainedphp_service2_v1"); }
/** * Поиск сотрудников * @param string $query * @param integer $limit * @return \Elasticquent\ElasticquentResultCollection */ public function searchWorkers(string $query, int $limit = 10) { return Worker::searchByQuery(['match' => ['search' => ['query' => $query, 'operator' => 'and']]], null, null, $limit)->load('organization'); // $result = Worker::searchByQuery( // ['match' => [ // 'search' => [ // 'query' => $query, // 'operator' => 'and', // ] // ]], // // ['orgs' => [ // 'terms' => [ // 'field' => 'organization_id', // 'size' => 10 // ], // 'aggregations' => [ // 'fio' => [ // 'terms' => [ // 'field' => 'fio', // ], // 'aggregations' => [ // 'top' => [ // 'top_hits' => [ // 'size' => 1 // ] // ] // ] // ] // ] // ]], null, 0 // ); // // $ids = []; // $aggregations = $result->getAggregations(); // foreach($aggregations['orgs']['buckets'] as $data) { // foreach($data['fio']['buckets'] as $data2) { // $ids[] = $data2['top']['hits']['hits'][0]['_id']; // } // } // $ids = array_slice($ids, 0, 20); // // return Worker::whereIn('id', $ids)->with('organization')->get(); }
function __construct() { if ($GLOBALS['db_config']) { $db_config = $GLOBALS['db_config']; self::$db = new mysqli($db_config['host'], $db_config['user'], $db_config['pswd'], $db_config['db']); self::$db->query('set names ' . $db_config['charset'] . ';'); $this->logger(__CLASS__, __METHOD__, 'db connect ..'); } if ($GLOBALS['redis']) { self::$redis = $GLOBALS['redis']; } if ($GLOBALS['memcached_config']) { $memcached_config = $GLOBALS['memcached_config']; //创建一个memcache对象 self::$memcached = new Memcached(); self::$memcached->addServer($memcached_config['host'], $memcached_config['port']) or die("Could not connect"); self::$memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true); //使用binary二进制协议 if ($memcached_config['user'] && $memcached_config['password']) { self::$memcached->setSaslAuthData($memcached_config['user'], $memcached_config['password']); } } }
public static function getWorkerOptions() { return Worker::orderBy('id', 'desc')->lists('name', 'id'); }
} } else { return true; } } return $this->sqlError('E0060'); } /** * Delete existing worker from account * @param account_id int User ID * @param id int Worker ID * @return bool **/ public function deleteWorker($account_id, $id) { $this->debug->append("STA " . __METHOD__, 4); $stmt = $this->mysqli->prepare("DELETE FROM {$this->table} WHERE account_id = ? AND id = ? LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $account_id, $id) && $stmt->execute() && $stmt->affected_rows == 1) { return true; } return $this->sqlError('E0061'); } } $worker = new Worker(); $worker->setDebug($debug); $worker->setMysql($mysqli); $worker->setMemcache($memcache); $worker->setShare($share); $worker->setConfig($config); $worker->setUser($user); $worker->setErrorCodes($aErrorCodes);
<?php //require_once 'Autoloader.php'; require "Worker.php"; $ws_worker = new Worker("websocket://0.0.0.0:2346"); $http_worker->count = 4; $ws_worker->onMessage = function ($connection, $data) { // 向客户端发送hello $data $connection->send('hello ' . $data); }; Worker::runAll(); echo "cccccccccccccccccccccccc\n";
// reindex $originWorkerListFlag = TRUE; } else { $workerList = array(); $workerList[0] = $worker; // currentworker $originWorkerFlag = TRUE; } } else { // done this way as PARAM_LIST may be reused $workerList = Worker::selectExpo($expo->expoid); $originExpoFlag = TRUE; } } else { // done this way as PARAM_LIST may be reused $workerList = Worker::selectStation($station->stationid); $originStationFlag = TRUE; } // this is the organizer get; need to finish with super/crew get if ($author->isCrewMember()) { // remove all workers // remove Organizers if Station // remove Supervisors if Expo for ($k = 0; $k < count($workerList); $k--) { $w = $workerList[$k]; if ($originStationFlag && $w->isSupervisor() || $originExpoFlag && $w->isOrganizer()) { continue; } unset($workerList[$k]); // remove in all other cases }
function actionWorkers() { //$worker_model = new Worker; $workers = Worker::model()->with('department', 'position')->findAll(); $this->render('workers', array('workers' => $workers)); }
class Person { private $name; public function set_name($name) { $this->name = $name; } public function get_name() { return $this->name; } } class Worker extends Person { private $salary; public function set_salary($salary) { $this->salary = $salary; } public function get_salary() { return $this->salary; } } $a_work = new Worker(); $a_work->set_name('Paul'); $a_work->set_salary(3500); $name = $a_work->get_name(); $salary = $a_work->get_salary(); echo $name . "µÄÔÂнΪ" . $salary;
public function register(){ parent::register(); }
public function editDuty(Duty $duty) { $this->layout->title = 'Edit Duty'; $worker_opt = Worker::getWorkerOptions(); $this->layout->main = View::make('admin.dashboard')->nest('content', 'duties.edit', compact('duty', 'worker_opt')); }