From 38206b776b100a3f5680a25565276ca429da3116 Mon Sep 17 00:00:00 2001 From: zhouxin Date: Wed, 5 Jul 2023 09:31:56 +0800 Subject: [PATCH] * Add method to get executable metric. --- module/metric/model.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/module/metric/model.php b/module/metric/model.php index 8b72782585..a6fe865630 100755 --- a/module/metric/model.php +++ b/module/metric/model.php @@ -54,7 +54,13 @@ class metricModel extends model } $metricList = array(); - foreach($fileList as $file) $metricList[basename($file)] = $file; + $excutableMetric = $this->getExecutableMetric(); + foreach($fileList as $file) + { + $code = rtrim(basename($file), '.php'); + if(!in_array($code, $excutableMetric)) continue; + $metricList[$code] = $file; + } return $metricList; } @@ -131,4 +137,31 @@ class metricModel extends model foreach($metricInstances as $metricInstance) $fieldList = array_merge($fieldList, $metricInstance->fieldList); return implode(',', array_unique($fieldList)); } + + /** + * Get executable metric code list. + * + * @access public + * @return array + */ + public function getExecutableMetric() + { + $currentWeek = date('w'); + $currentDay = date('d'); + $now = date('H:i'); + + $metricList = $this->select('code,collectConf')->from(TABLE_BASICMEAS)->where('collectType')->eq('crontab')->fetchAll(); + + $excutableMetric = array(); + foreach($metricList as $metric) + { + $collectConf = json_decode($metric->collectConf); + if($collectConf->type == 'week' and strpos($collectConf->week, $currentWeek) === false) continue; + if($collectConf->type == 'month' and strpos($collectConf->month, $currentDay) === false) continue; + if($now >= $metric->execTime) continue; + + $excutableMetric[] = $metric; + } + return $excutableMetric; + } }