def request_task(self): self.debug('Requesting task from server.') taskid = self.client.next_task(self.hostname) if taskid > 0: self.info('Task %d was received from server.' % taskid) db = Session() task = db.query(Task).filter_by(id=taskid).first() db.expunge(task) db.close() if task: self.num_thread_lock.acquire() self.running_tasks[taskid] = task self.num_thread_lock.release() self._pre_task(task) if not self._run_task(task): self._clean_up_task(task) self._no_tasks = False else: self.debug('No task was received from server.') self._no_tasks = True
def monitor_connect(self, task_id): self.debug('Monitor for task %d has connected.' % task_id) db = Session() task = self.running_tasks[task_id] db.add(task) db.add(task.log) task_data = {} task_data['command'] = task.run_command tries = 0 while tries < 3: try: task_data['gid'] = pwd.getpwnam(task.job.owner)[3] task_data['uid'] = pwd.getpwnam(task.job.owner)[2] break except KeyError: tries += 1 task_data['stdout_file_path'] = task.log._stdout_file_path() task_data['stderr_file_path'] = task.log._stderr_file_path() db.close() return task_data
def monitor_probe(self, task_id, probes): self.debug("Logging probe for %d" % task_id) task = self.running_tasks[task_id] db = Session() probe = TaskProbe() db.add(probe) cattle = self.cattle probe.task_id = task_id probe.memory = probes['memory'] probe.pcpu = probes['pcpu'] probe.pid = probes['pid'] #probe.cattle_id = task.log.cattle_id probe.time = datetime.datetime.now() probe.probes = probes probe.cattle_id = cattle.id probe.task_log_id = task.log.id db.commit() probe_id = probe.id db.expunge(probe) db.close() return probe_id