def start(self): d = { "command": self._command, "updated_at": utcnow(), "created_at": utcnow(), "status": RunStats.running, } if self._args: d.update({"arguments": self._args}) r = self.mongo.create_documents(RUNSTATSMONITOR_COLLECTION_NAME, [d]) self.task_id = r[0] return self.task_id
def start(self): d = { 'command': self._command, 'updated_at': utcnow(), 'created_at': utcnow(), 'status': RunStats.running } if self._args: d.update({'arguments': self._args}) r = self.mongo.create_documents(RUNSTATSMONITOR_COLLECTION_NAME, [d]) self.task_id = r[0] return self.task_id
def fail(self, err_msg): self.mongo.update_fields(RUNSTATSMONITOR_COLLECTION_NAME, {'_id': self.task_id}, { 'updated_at': utcnow(), 'status': RunStats.failed, 'err_msg': err_msg })
def send_alert_email(msg): get_logger().info("try to send runner alert email...") if opt.debug: receivers = "*****@*****.**" else: receivers = ",".join(RECEIVERS) content = dedent(""" time: {dt} command: {command} error: {err} """.format(dt=utcnow().strftime("%Y-%m-%dT%H:%M:%S"), command=opt.command, err=msg)) opt.sender.send_email( mail_from="*****@*****.**", mail_to=receivers, subject="DATA Monitoring: Runner got critical error", content=content, )
def fail(self, err_msg): self.mongo.update_fields( RUNSTATSMONITOR_COLLECTION_NAME, {"_id": self.task_id}, {"updated_at": utcnow(), "status": RunStats.failed, "err_msg": err_msg}, )
def clean_logs_by_timedelta(self, timedelta): get_logger().info("clean_logs_by_timedelta for timedelta %s", timedelta) self.collection.remove({"updated_at": {"$lt": utcnow() + timedelta}})
def success(self): self.mongo.update_fields( RUNSTATSMONITOR_COLLECTION_NAME, {"_id": self.task_id}, {"updated_at": utcnow(), "status": RunStats.successed}, )
def clean_logs_by_timedelta(self, timedelta): get_logger().info('clean_logs_by_timedelta for timedelta %s', timedelta) self.collection.remove({'updated_at': {'$lt': utcnow() + timedelta}})
def success(self): self.mongo.update_fields(RUNSTATSMONITOR_COLLECTION_NAME, {'_id': self.task_id}, { 'updated_at': utcnow(), 'status': RunStats.successed })