- self._stop(job, "misbehaving. Reason: " + str(e))
-
- def _update_job(self, job):
- """
- Tries to execute update() on specified job.
- This cannot fail thus it is catching every exception.
- If job.update() returns False, number of retries_left is decremented.
- If there are no more retries, job is stopped.
- Job is also stopped if it throws an exception.
- This is also updating job run time chart.
- Return False if job is stopped
- :param job: object
- :return: boolean
- """
- t_start = time.time()
- # check if it is time to execute job update() function
- if job.timetable['next'] > t_start:
- debug("it is not a time to invoke update on", job.chart_name)
- return True
- try:
- if self.first_run:
- since_last = 0
- else:
- since_last = int((t_start - job.timetable['last']) * 1000000)
- if not job.update(since_last):
- if job.retries_left <= 0:
- self._stop(job, "update failed")
- return False
- job.retries_left -= 1
- job.timetable['next'] += job.timetable['freq']
- return True
- except AttributeError:
- self._stop(job, "no update")
- return False
- except (UnboundLocalError, Exception) as e:
- self._stop(job, "misbehaving. Reason: " + str(e))
- return False
- t_end = time.time()
- job.timetable['next'] = t_end - (t_end % job.timetable['freq']) + job.timetable['freq']
- # draw performance graph
- run_time = str(int((t_end - t_start) * 1000))
- debug(job.chart_name, "updated in", run_time)
- sys.stdout.write("BEGIN netdata.plugin_pythond_" + job.chart_name + " " + str(since_last) + '\n')
- sys.stdout.write("SET run_time = " + run_time + '\n')
- sys.stdout.write("END\n")
- # sys.stdout.flush()
- job.timetable['last'] = t_start
- job.retries_left = job.retries
- self.first_run = False
- return True