public function getTimeDue($releaseDay, $releaseTime) { $tm = null; if ($releaseDay && $releaseTime) { $schedDay = CalemScheduleInfo::decode($releaseDay); $schedTime = CalemScheduleTimeInfo::decode($releaseTime); $dueTime = $schedTime->getNextDueTime(null, $schedDay); $tm = $dueTime ? CalemText::getServerDateTime($dueTime) : null; } return $tm; }
/** * Figure out next time due */ public function updateNextDueTime($jobRow) { $schedDay = CalemScheduleInfo::decode($jobRow['release_day']); $schedTime = CalemScheduleInfo::decode($jobRow['release_time']); $dueTime = CalemText::parseServerDateTime($jobRow['time_due']); $newTime = $schedTime->getNextDueTime($dueTime, $schedDay); try { $this->dbo->setValue('time_due', CalemText::getServerDateTime($newTime)); $this->dbo->setIdForUpdate($jobRow['id']); $this->dbo->update(); } catch (Exception $e) { $this->logger->error("Error in updating job row=" . var_export($jobRow, true) . ", msg=" . $e->getMessage()); } }
public function getDataChanged() { $mt = filemtime($this->dataFile); if (mktime() - $mt <= $this->conf['ttl']) { return false; } $rtn = false; try { $stime = CalemText::getServerDateTime($mt); $cnt = $this->dbo->getCountBySqlParam($this->getSqlCheck(), array($stime)); $rtn = $cnt > 0; } catch (CalemDboDataNotFoundException $e) { } return $rtn; }
public function set($sem) { $ar = array("expire_time" => CalemText::getServerDateTime($sem->getExpireTime())); try { $ps = $this->dbo->fetchById($sem->getId()); //Doing an update here. $this->dbo->setChangeBulk($ar); $this->dbo->setIdForUpdate($sem->getId()); $this->dbo->update(); } catch (CalemDboDataNotFoundException $e) { //Doing an insertion here. $ar['id'] = $sem->getId(); $this->dbo->setChangeBulk($ar); $this->dbo->insert(); } }
/** * PM dependency map to load up */ public function getPdm() { $pdm = null; $cache = CalemFactory::getDataCacheManager(); $pdmInfo = $cache->load('pdm'); if ($pdmInfo) { if ($this->pdmUpToDate($pdmInfo)) { $pdm = $pdmInfo['pdm']; } } if (!$pdm) { //Create PDM and save it. $timestamp = CalemText::getServerDateTime(); $pdm = $this->buildPdm(); $cache->save(array('timestamp' => $timestamp, 'pdm' => $pdm), 'pdm'); } return $pdm; }
/** * If the scheduler cannot secure a semaphore do not proceed. */ public function execute() { $sem = $this->semBo->get(self::SemSchedulerId); if ($sem != null && $sem->getExpireTime() > gmmktime()) { $this->logger->debug("A semaphore is still on. Abort this run."); return; } //Secure a semaphore for this run $this->setSemaphore(); //Cycle through jobs try { $jobs = $this->jobBo->getDueJobList(); if (!$jobs) { $this->semBo->clear(self::SemSchedulerId); return; } foreach ($jobs as $job) { //Extend script time and semaphore if ($this->conf['task_script_time']) { set_time_limit($this->conf['task_script_time']); } $this->setSemaphore(); //run one job. if ($this->logger->isDebugEnabled()) { $this->logger->debug("starting job: " . var_export($job, true)); } try { $this->jobBo->updateNextDueTime($job); $startTime = CalemText::getServerDateTime(); $rtn = $this->jobBo->executeJob($job); $endTime = CalemText::getServerDateTime(); $this->jobBo->addJobRun($job, $startTime, $endTime, $rtn); } catch (Exception $e) { $this->logger->error("Error in starting job=" . $job['id'] . ", msg=" . $e->getMessage()); } } } catch (Exception $e) { $this->logger->error("Error in starting jobs, msg=" . $e->getMessage()); } $this->semBo->clear(self::SemSchedulerId); }
/** * Manual-gen a req */ public function manualGenOrderRequest($inId, $reqRow) { $inDbo = CalemFactory::getDbo('inventory'); $inRow = $inDbo->fetchById($inId); if (!$inRow['qty_to_order']) { return; } //In case it's processed already //Figure out the due date $initRow = $this->conf['in_order_gen']['req_manual']['init']; foreach ($initRow as $key => $val) { if (!$reqRow[$key]) { $reqRow[$key] = $val; } } $dueDate = $this->getReqDueDateByWo($inId); if ($dueDate) { $reqRow['due_date'] = CalemText::datetimeToDate($dueDate); } $reqRow['request_time'] = CalemText::getServerDateTime(); $reqBo = new CalemReqBo(); $reqId = $reqBo->createInOrderRequest($reqRow, $inId, $inRow['qty_to_order'], $inRow['uom_id']); }
/** * To use CalemWoDbo for business logic reuse. */ public function releasePm($dueDate, $finishTime, $pmRow, $pmAssetRow) { //Counting dates $woRow = array(); $woRow['planned_start_time'] = CalemText::getServerDateTime($dueDate); $woRow['planned_finish_time'] = CalemText::getServerDateTime($finishTime); $woRow['status_id'] = $this->releaseConf['wo_status']; $woRow['orig_time'] = CalemText::getServerDateTime(); //It's today $woRow['time_needed'] = $woRow['planned_finish_time']; $woRow = $this->copyPmToWo($woRow, $pmRow, $pmAssetRow); //Check for minimum fields to fill if not set foreach ($this->wogenConf['wo_min_default'] as $fld => $value) { if (!$woRow[$fld]) { $woRow[$fld] = $value; } } $woRow = $this->woDbo->beforeInsert('workorder', $woRow, null, null); //Start a transaction here $this->woDbo->unsetId(); //So a new Id is generated $this->woDbo->beginTransaction(); try { $this->woDbo->setChangeBulk($woRow); $woId = $this->woDbo->insert(); $this->woDbo->onDataInserted($woId, 'workorder', $woRow, null, null); //Also recording release dates at PM $this->setPmReleaseDate($dueDate, $pmRow, $pmAssetRow); $this->woDbo->commit(); } catch (Exception $ex) { $this->logger->error("Error in releasing pm: " . var_export($woRow, true)); $this->woDbo->rollback(); $woId = null; } return $woId; }
public function getSemaphore() { try { $row = $this->semDbo->fetchById($this->conf['semaphore_id']); if ($row['expiration']) { $time = CalemText::parseServerDateTime($row['expiration']); } else { $time = 0; } if ($time > mktime()) { if ($this->logger->isInfoEnabled()) { $this->logger->info("Cannot start wo generation, semaphore is not expired: " . date('Y-m-d H:i:s', $time)); } return false; } $this->extendSemaphore(); } catch (CalemDboDataNotFoundException $ex) { $this->semDbo->setChangeBulk(array('id' => $this->conf['semaphore_id'], 'expiration' => CalemText::getServerDateTime($this->getSemExpiration()))); $this->semDbo->insert(); } return true; }
/** * Order generation check */ public function generateOrderRequest($inRow) { if ($inRow['qty_to_order'] > 0 && $inRow['order_gen_id'] == 'inog_auto') { $inOrderGenBo = new CalemInOrderGenBo(); $inOrderGenBo->autoGenOrderRequest($inRow['id'], $inRow['qty_to_order'], $inRow['uom_id'], $inRow['owner_user_id'], CalemText::getServerDateTime()); } }