Esempio n. 1
0
    def report(self, is_test=False):
        def _check_need(time):
            _time = str(int(time.split(":")[0]))
            if _time == self.time_to_check:
                return True
            else:
                return False

        def _update_check_time():
            i = REPORT_TIME.index(self.time_to_check)
            if i >= len(REPORT_TIME) - 1:
                new_time = REPORT_TIME[0]
            else:
                new_time = REPORT_TIME[i + 1]
            self.time_to_check = new_time

            conn = MongoConn(config=MONGODB_CONFIG)
            coll = conn.get_coll("system_var_coll")
            coll.update({"key": "report_check_time"}, {"$set": {"value": new_time}})

        _date = datetime.now().strftime("%Y-%m-%d")
        _time = datetime.now().strftime("%H:%M:%S")
        if _check_need(_time):
            _update_check_time()

            # 执行
            info = self.get_info(is_test)

            send_message(subject="定时任务执行报告", content=info, attachments=[])
            conn = MongoConn(config=MONGODB_CONFIG)
            coll = conn.get_coll("report_info_coll")
            coll.insert(dict(date=_date, time=_time, datetime=datetime.now(), info=info))

        else:
            pass
Esempio n. 2
0
        def _update_check_time():
            i = REPORT_TIME.index(self.time_to_check)
            if i >= len(REPORT_TIME) - 1:
                new_time = REPORT_TIME[0]
            else:
                new_time = REPORT_TIME[i + 1]
            self.time_to_check = new_time

            conn = MongoConn(config=MONGODB_CONFIG)
            coll = conn.get_coll("system_var_coll")
            coll.update({"key": "report_check_time"}, {"$set": {"value": new_time}})
Esempio n. 3
0
    def _init_check_time_from_db(self):

        conn = MongoConn(config=MONGODB_CONFIG)
        coll = conn.get_coll("system_var_coll")
        doc = coll.find_one(filter=dict(key="report_check_time"))
        if not doc:
            # 寻找最近将来时间点 默认有序
            _now_hour = datetime.now().hour
            for h in REPORT_TIME:
                if _now_hour - int(h) > 0:
                    continue
                else:
                    self.time_to_check = h
                    break
            if not self.time_to_check:
                self.time_to_check = REPORT_TIME[0]
            coll.insert(dict(key="report_check_time", value=self.time_to_check))
        else:
            self.time_to_check = doc['value']