예제 #1
0
	def run(self):
		"""
		Run the thread, comsume from queue, execute Command, add to queue.
		Continue until it receives a shutdown WorkUnit.
		"""
		while True:
			work_unit = self.work_queue.get()
			self.start_working()
			if work_unit.isShutdown():
				log.debug("Received shutdown request.")
				self.stop_working()
				return
			log.info("Processing: %s" % (work_unit))

			try:
				new_work_units = work_unit.command.execute(work_unit)
			except Exception, err:
				log.warn("Unexpected Exception from %s: %s\n%s " % (work_unit.command,
						err, traceback.format_exc()))
				Statistics.getObj().incr('Thread', 'unknown_failure')
				self.stop_working()
				continue

			if new_work_units:
				for new_work_unit in new_work_units:
					self.work_queue.put(new_work_unit)
			self.stop_working()
예제 #2
0
	def record(self, name):
		"""
		Record a status message from a command.
		"""
		group_name = self.group.name if self.group else ''
		Statistics.getObj().incr(group_name, name)
예제 #3
0
	def _print_stats(self):
		" Print statistics to stdout. "
		stats = Statistics.getObj().details()
		for (group, values) in stats.iteritems():
			print '\n'.join(['%-35s %s' % ("%s %s" % (group, k), v) for 
					(k, v) in values.iteritems() ])