示例#1
0
 public function childModels($active = true)
 {
     if ($active) {
         $active = 1;
     } else {
         $active = [0, 1];
     }
     $models = [];
     $models['Sensor'] = Sensor::find()->where(['object_id' => $this->id, 'active' => $active])->all();
     $models['ResourceReference'] = ResourceReference::find()->where(['resource_id' => $this->id, 'active' => $active])->all();
     return $models;
 }
示例#2
0
 public function sensorHandlerHead($headId)
 {
     $limitPerTick = 10;
     $tickCallback = [$this, 'tickCallback'];
     $ticks = 0;
     $self = $this;
     $exitStatus = 0;
     $timer = $this->loop->addPeriodicTimer(rand(1, 10) / 1000, function () use($self, $headId, $limitPerTick, $tickCallback, &$exitStatus, &$ticks, &$timer) {
         $ticks++;
         $sensorsToCheck = Sensor::find()->where(['and', ['active' => 1], '[[next_check]] <= "' . gmdate("Y-m-d G:i:s") . '"'])->orderBy(['next_check' => SORT_ASC])->limit($limitPerTick)->all();
         $skipCount = 0;
         $itemCount = count($sensorsToCheck);
         $sleepAfter = $itemCount === 0;
         foreach ($sensorsToCheck as $sensor) {
             if ($self->checkFailTaken('Sensor.' . $sensor->id . '-' . $sensor->next_check, $headId)) {
                 $skipCount++;
                 // echo "Another head is checking {$sensor->id}...".PHP_EOL; flush();
                 continue;
             }
             //  echo "{$headId} checking {$sensor->id}...".PHP_EOL; flush();
             if (!$sensor->dataObject->check($self->loop)) {
                 $sleepAfter = true;
             }
         }
         if ($skipCount === $limitPerTick) {
             $self->loop->cancelTimer($timer);
             $exitStatus = 1;
         }
         if (call_user_func($tickCallback, $ticks)) {
             $self->loop->cancelTimer($timer);
         }
         if ($sleepAfter) {
             sleep(5);
         }
     });
     $this->loop->run();
     Yii::$app->end($exitStatus);
 }
示例#3
0
 public function parentModels()
 {
     $models = [];
     $models['Sensor'] = Sensor::find()->where(['id' => $this->object_id])->all();
     $models['Service'] = Service::find()->where(['id' => $this->object_id])->all();
     $models['ServiceReference'] = ServiceReference::find()->where(['id' => $this->object_id])->all();
     $models['Server'] = Server::find()->where(['id' => $this->object_id])->all();
     $models['Site'] = Site::find()->where(['id' => $this->object_id])->all();
     return $models;
 }
示例#4
0
 public function childModels($careAboutActive = true)
 {
     if ($careAboutActive) {
         $active = 1;
     } else {
         $active = [0, 1];
     }
     $models = [];
     $models['Resource'] = Resource::find()->where(['object_id' => $this->id, 'active' => $active])->all();
     $models['Sensor'] = Sensor::find()->where(['object_id' => $this->id, 'active' => $active])->all();
     $models['Service'] = Service::find()->where(['id' => $this->service_id, 'active' => $active])->all();
     $models['ResourceReference'] = ResourceReference::find()->where(['object_id' => $this->id, 'active' => $active])->all();
     if ($serviceProvider = Registry::getObject($this->object_id)) {
         if (!$careAboutActive || !empty($serviceProvider->active)) {
             $models['ServiceProvider'] = [$serviceProvider];
         }
     }
     return $models;
 }
示例#5
0
 public function getSensor($id)
 {
     if (empty($this->model) || empty($this->model->primaryKey)) {
         return false;
     }
     $sensor = SensorModel::find()->where(['object_id' => $this->model->primaryKey, 'system_id' => $id])->one();
     if (!$sensor) {
         return false;
     }
     return $sensor->dataObject;
 }
示例#6
0
 public function childModels($active = true)
 {
     if ($active) {
         $active = 1;
     } else {
         $active = [0, 1];
     }
     $models = [];
     $models['Site'] = Site::find()->where(['provider_id' => $this->id, 'active' => $active])->all();
     $models['Server'] = Server::find()->where(['provider_id' => $this->id, 'active' => $active])->all();
     $models['Sensor'] = Sensor::find()->where(['object_id' => $this->id, 'active' => $active])->all();
     return $models;
 }