本文整理汇总了PHP中Job::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Job::set方法的具体用法?PHP Job::set怎么用?PHP Job::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Job
的用法示例。
在下文中一共展示了Job::set方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addGCodeFile
public function addGCodeFile($file, $qty = 1)
{
$jobs = array();
for ($i = 0; $i < $qty; $i++) {
$sort = db()->getValue("SELECT max(id)+1 FROM jobs");
$job = new Job();
$job->set('user_id', User::$me->id);
$job->set('queue_id', $this->id);
$job->set('file_id', $file->id);
$job->set('name', $file->get('path'));
$job->set('status', 'available');
$job->set('created_time', date("Y-m-d H:i:s"));
$job->set('user_sort', $sort);
$job->save();
$jobs[] = $job;
}
return $jobs;
}
示例2: fix_temp_data
<?php
include "../../extensions/global.php";
include "../patches.php";
$patchNumber = 12;
start_patch();
if (!patch_exists($patchNumber)) {
// Fix the temperature fields:
$rs = db()->query("SELECT * from jobs");
while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
$job = new Job($row['id']);
$fixed_data = fix_temp_data($job->get('temperature_data'));
$job->set('temperature_data', $fixed_data);
$job->save();
}
$rs = db()->query("SELECT * from bots");
while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
$bot = new Bot($row['id']);
$fixed_data = fix_temp_data($bot->get('temperature_data'));
$bot->set('temperature_data', $fixed_data);
$bot->save();
}
$expandTemperatureData = "\n\t\tALTER TABLE jobs\n \t\tMODIFY COLUMN temperature_data longtext NOT NULL";
db()->execute($expandTemperatureData);
$expandTemperatureData = "\n\t\tALTER TABLE bots\n \t\tMODIFY COLUMN temperature_data longtext NOT NULL";
finish_patch($patchNumber, "Expanded temperature data fields");
}
function fix_temp_data($data)
{
if (strlen($data) == 0) {
return "";
示例3: update_sort
public function update_sort()
{
$this->assertLoggedIn();
if (!$this->args('jobs')) {
die("Error: You didn't pass any jobs in.");
}
$jobs = explode(",", $this->args('jobs'));
if (count($jobs) < 1) {
die("Error: You need to pass in at least 2 jobs.");
}
//load up our ids.
$jids = array();
foreach ($jobs as $job) {
$jarray = explode("_", $job);
$jid = (int) $jarray[1];
if (!$jid) {
die("Error: format must be a csv of job_### where ### is the job id.");
}
$jids[] = $jid;
}
//find our our current max
$sql = "SELECT min(user_sort) FROM jobs WHERE id IN (" . implode($jids, ",") . ")";
$min = (int) db()->getValue($sql);
//now actually update.
foreach ($jids as $jid) {
$job = new Job($jid);
if ($job->get('user_id') == User::$me->id) {
$job->set('user_sort', $min);
$job->save();
$min++;
} else {
die("Error: Job {$jid} is not your job.");
}
}
die("OK");
}
示例4: set
/**
* 设置属性
*
* @param string $key
* @param string $val
*/
public function set($key, $val)
{
parent::set($key, $val);
}
示例5: start_retrieval_job
function start_retrieval_job(Job $job, DateTime $start_time)
{
$oResult = client()->initiateJob(array('accountId' => '-', 'vaultName' => VAULT, 'ArchiveId' => $job->get('archive_id'), 'RetrievalByteRange' => $job->get('start') . "-" . $job->get('end'), 'Type' => 'archive-retrieval'));
$job->set('start_time', $start_time);
$job->set('running', 1);
$job->set('jobId', $oResult->get('jobId'));
}
示例6: grabJob
/**
* @param $job Job
* @param $can_slice bool
* @return Job
* @throws Exception
*/
public function grabJob($job, $can_slice = true)
{
$grabAttemptSQL = "\n UPDATE jobs\n SET bot_id =\n CASE\n WHEN bot_id=0\n THEN\n ?\n ELSE\n bot_id\n END\n WHERE id = ?\n ";
// Attempt to grab the job unless another bot already has
db()->execute($grabAttemptSQL, array($this->id, $job->id));
$job = new Job($job->id);
// Reload the job
if ($job->get('bot_id') != $this->id) {
// We didn't grab it in time.
throw new Exception("Unable to lock job #{$job->id}");
}
$job->setStatus('taken');
$job->set('taken_time', date('Y-m-d H:i:s'));
$job->save();
//do we need to slice this job?
if (!$job->getFile()->isHydrated() && $can_slice) {
//pull in our config and make sure it's legit.
$config = $this->getSliceConfig();
if (!$config->isHydrated()) {
$job->setStatus('available');
$job->set('bot_id', 0);
$job->set('taken_time', 0);
$job->save();
throw new Exception("This bot does not have a slice engine + configuration set.");
}
//is there an existing slice job w/ this exact file and config?
$sj = SliceJob::byConfigAndSource($config->id, $job->get('source_file_id'));
if ($sj->isHydrated()) {
//update our job status.
$job->set('slice_job_id', $sj->id);
$job->set('slice_complete_time', $job->get('taken_time'));
$job->set('file_id', $sj->get('output_id'));
$job->save();
} else {
//nope, create our slice job for processing.
$sj->set('user_id', User::$me->id);
$sj->set('job_id', $job->id);
$sj->set('input_id', $job->get('source_file_id'));
$sj->set('slice_config_id', $config->id);
$sj->set('slice_config_snapshot', $config->getSnapshot());
$sj->set('add_date', date("Y-m-d H:i:s"));
$sj->setStatus('available');
$sj->save();
//update our job status.
$job->setStatus('slicing');
$job->set('slice_job_id', $sj->id);
$job->save();
}
}
$log = new JobClockEntry();
$log->set('job_id', $job->id);
$log->set('user_id', User::$me->id);
$log->set('bot_id', $this->id);
$log->set('queue_id', $job->get('queue_id'));
$log->set('start_date', date("Y-m-d H:i:s"));
$log->setStatus('working');
$log->save();
$this->set('job_id', $job->id);
$this->setStatus(BotState::Working);
$this->set('last_seen', date("Y-m-d H:i:s"));
$this->save();
return $job;
}
示例7: api_updatejobprogress
public function api_updatejobprogress()
{
$job = new Job($this->args('job_id'));
if (!$job->isHydrated()) {
throw new Exception("Job does not exist.");
}
$bot = $job->getBot();
if (!$bot->isHydrated()) {
throw new Exception("Bot does not exist.");
}
if (!$bot->isMine()) {
throw new Exception("This is not your bot.");
}
if (!$job->getQueue()->isMine()) {
throw new Exception("This job is not in your queue.");
}
$job->set('progress', (double) $this->args('progress'));
$job->save();
$bot->set('last_seen', date("Y-m-d H:i:s"));
$bot->save();
return $job->getAPIData();
}
示例8: update_sort
public function update_sort()
{
$this->assertLoggedIn();
if (!$this->args('jobs')) {
die("Error: You didn't pass any jobs in.");
}
$jobs = explode(",", $this->args('jobs'));
if (count($jobs) < 1) {
die("Error: You need to pass in at least 2 jobs.");
}
//load up our ids.
$jobIds = preg_filter('/^job_(\\d+)$/', '$1', $jobs);
$jobs = array();
// Only grab jobs that exist and are ours
foreach ($jobIds as $id) {
/** @var Job $job */
$job = new Job($id);
if ($job->isHydrated() && $job->isMine()) {
$jobs[$id] = $job->get('user_sort');
}
}
// Sort the values, but not the keys
$values = array_values($jobs);
sort($values);
$jobs = array_combine(array_keys($jobs), $values);
// Now actually update
foreach ($jobs as $id => $sort) {
/** @var Job $job */
$job = new Job($id);
$job->set('user_sort', $sort);
$job->save();
}
die(print_r($jobs, true));
}
示例9: api_downloadedjob
public function api_downloadedjob()
{
$job = new Job($this->args('job_id'));
if (!$job->isHydrated()) {
throw new Exception("Job does not exist.");
}
$bot = $job->getBot();
if (!$bot->isHydrated()) {
throw new Exception("Bot does not exist.");
}
if (!$bot->isMine()) {
throw new Exception("This is not your bot.");
}
if (!$job->getQueue()->isMine()) {
throw new Exception("This job is not in your queue.");
}
$job->setStatus('taken');
$job->set('downloaded_time', date("Y-m-d H:i:s"));
$job->set('progress', 0);
// clear our download progress meter.
$job->save();
// This returns the new bot, but it's currently not needed
$this->_markBotAsSeen($bot);
return $job->getAPIData();
}
示例10: addFileToQueue
/**
* @param $queue_id int
* @param $file StorageInterface
* @return Job
*/
public static function addFileToQueue($queue_id, $file)
{
$sortSQL = "SELECT max(id)+1 FROM jobs WHERE user_id = ?";
$sort = db()->getValue($sortSQL, array(User::$me->id));
// Special case for first sort value
if ($sort == "") {
$sort = 1;
}
$job = new Job();
$job->set('user_id', User::$me->id);
$job->set('queue_id', $queue_id);
$job->set('source_file_id', $file->id);
if ($file->isGCode()) {
$job->set('file_id', $file->id);
}
if ($file->isMakerbot()) {
$job->set('file_id', $file->id);
}
$job->setName($file->get('path'));
$job->setStatus('available');
$job->set('created_time', date("Y-m-d H:i:s"));
$job->set('user_sort', $sort);
$job->save();
return $job;
}
示例11: function
})->conditions(array('jobid' => '[0-9]'));
/* Jobs - Finish a job (with buildstatus and buildreason) */
$app->post('/jobs/:jobid/finish', 'isAllowed', function ($jobid) use($app) {
if (!isset($_POST['buildstatus']) || !isset($_POST['buildreason'])) {
textResponse(400, 'Post data missing');
}
$job = new Job($jobid);
if ($job === false) {
textResponse(204);
}
$machine = new Machine(Session::getMachineId());
if (!$machine->hasJob($job->getJobId())) {
textResponse(403, 'Job not assigned to you');
}
$job->unset('machine');
$job->set('buildstatus', $_POST['buildstatus']);
$job->set('buildreason', $_POST['buildreason']);
$job->moveToQueue('archivequeue');
jsonResponse(200, $job->getJobData());
})->conditions(array('jobid' => '[0-9]'));
/* Jobgroup - List details of jobgroup */
$app->get('/group/:groupid/', 'isAllowed', function ($groupid) use($app) {
$jobgroup = new Jobgroup($groupid);
if (!$jobgroup->exists()) {
textResponse(404, 'Jobgroup not found');
}
jsonResponse(200, $jobgroup->getGroupInfo());
});
/* 404 - not found */
$app->notFound(function () use($app) {
textResponse(404, 'Not found');
示例12: api_webcamupdate
public function api_webcamupdate()
{
if ((int) $this->args('job_id')) {
$job = new Job($this->args('job_id'));
if (!$job->isHydrated()) {
throw new Exception("Job does not exist.");
}
$bot = $job->getBot();
if (!$bot->isHydrated()) {
throw new Exception("Bot does not exist.");
}
if (!$job->getQueue()->isMine()) {
throw new Exception("This job is not in your queue.");
}
} else {
if ((int) $this->args('bot_id')) {
$bot = new Bot($this->args('bot_id'));
if (!$bot->isHydrated()) {
throw new Exception("Bot does not exist.");
}
$job = new Job();
} else {
throw new Exception("You must pass in either a bot or job id.");
}
}
if (!$bot->isMine()) {
throw new Exception("This is not your bot.");
}
if (!empty($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
//upload our file
$file = $_FILES['file'];
$this->ensureGoodFile($file);
//does it match?
if (!preg_match("/\\.jpg\$/i", $file['name'])) {
throw new Exception("The file must end in .jpg");
}
//is it a real image?
$size = getimagesize($file['tmp_name']);
if (!$size[0] || !$size[1]) {
throw new Exception("The file is not a valid image.");
}
//okay, we're good.. do it.
if ($job->isHydrated()) {
$data_file = Storage::newFile();
} else {
$data_file = $bot->getWebcamImage();
}
$data_file->set('user_id', User::$me->id);
$data_file->upload($file['tmp_name'], StorageInterface::getNiceDir($file['name']));
//if we have a job, save our new image.
if ($job->isHydrated()) {
$job->set('webcam_image_id', $data_file->id);
$ids = json::decode($job->get('webcam_images'));
if ($ids == NULL) {
$ids = array();
$ids[time()] = $data_file->id;
} else {
$index = time();
$ids->{$index} = $data_file->id;
}
$job->set('webcam_images', json::encode($ids));
}
//always pull the latest image in for the bot.
$bot->set('webcam_image_id', $data_file->id);
} else {
throw new Exception("No file uploaded.");
}
//did we get temperatures?
$this->_updateTemperatures($this->args('temperatures'), $bot, $job);
//update our job info.
if ($this->args('progress') && $job->isHydrated()) {
$job->set('progress', (double) $this->args('progress'));
}
//only save the job if its real.
if ($job->isHydrated()) {
$job->save();
}
//update our bot info
$bot = $this->_markBotAsSeen($bot);
//what kind of data to send back.
if ($job->isHydrated()) {
return $job->getAPIData();
} else {
return $bot->getAPIData();
}
}