本文整理汇总了PHP中Scheduler::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Scheduler::model方法的具体用法?PHP Scheduler::model怎么用?PHP Scheduler::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scheduler
的用法示例。
在下文中一共展示了Scheduler::model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model = Scheduler::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例2: actionIndex
public function actionIndex(array $task = array(), $manual = false)
{
foreach (Scheduler::model()->findAll(array('order' => '`order` ASC', 'condition' => 't.active=1' . (count($task) ? ' AND t.id IN (' . implode(',', $task) . ')' : ''))) as $schedule) {
echo $schedule->module . "::" . $schedule->task . "Task()\n";
if ($manual == false) {
$data_value = array();
preg_match('/^([0-9]+)([a-zA-Z]+)$/is', $schedule->period, $data_value);
if (count($data_value) < 3 || empty($data_value[0]) || empty($data_value[1]) || empty($data_value[2])) {
continue;
}
switch ($data_value[2]) {
case 's':
$date_type = 'SECOND';
break;
case 'i':
$date_type = 'MINUTE';
break;
case 'h':
$date_type = 'HOUR';
break;
case 'd':
$date_type = 'DAY';
break;
case 'm':
$date_type = 'MONTH';
break;
case 'y':
$date_type = 'YEAR';
break;
default:
$date_type = 'HOUR';
}
$sql = "SELECT IF(DATE_ADD(last_run, INTERVAL " . intval($data_value[1]) . " " . $date_type . ")<=UTC_TIMESTAMP(), 'yes', 'no') as need_start FROM " . Scheduler::model()->tableName() . " WHERE id=" . $schedule->id;
$need_start = Yii::app()->db->createCommand($sql)->queryScalar();
if ($need_start == 'no') {
echo "no need start task\n\n";
continue;
}
}
echo "start task\n";
$module = $schedule->module . 'Scheduler';
$task = $schedule->task . 'Task';
$error = '';
try {
Yii::app()->{$module}->{$task}($schedule->data);
} catch (CException $e) {
$error = $e->getMessage();
}
if (!empty($error)) {
echo "error with start task\nerror text: " . $error . "\n\ncontinued\n\n";
continue;
}
if ($manual) {
echo "task finished\n\n";
} else {
if ($schedule->task == 'exchangeRates' && $schedule->last_run == '1970-01-01 00:00:00') {
$utc_run = Yii::app()->db->createCommand("SELECT DATE_ADD(DATE_SUB(UTC_DATE(), INTERVAL 4 HOUR), INTERVAL 2 MINUTE)")->queryScalar();
$schedule->last_run = $utc_run;
} else {
$schedule->last_run = new CDbExpression('UTC_TIMESTAMP()');
}
if ($schedule->save()) {
echo "task finished, last start date updated\n\n";
} else {
echo "error with update task\n\n";
}
}
}
}