Exemplo n.º 1
0
 def process_commands(self):
     for command in self.db.master_commands.find():
         if command['command'] in self.commands:
             utils.info('Got command: {0}'.format(command['command']))
             self.commands[command['command']](command['params'])
         else:
             utils.error('Command not recognised: {0} - deleting'.format(command['command']))
         self.db.master_commands.remove({'_id': command['_id']})
Exemplo n.º 2
0
 def job_is_completed(self, job):
     if job['fragments'] is not None:
         for fragment_id in job['fragments']:
             fragment = self.db.fragments.find_one({'_id' : fragment_id})
             if fragment is not None:
                 if not (fragment['status'] == 'completed' or fragment['status'] == 'cancelled'):
                     return False
             else:
                 utils.error('Fragment {0} does not exist'.format(fragment_id))
     return True
Exemplo n.º 3
0
    def scan_jobs(self):
        try:
            job_dirs = os.listdir(self.controller.job_dir)
        except:
            utils.error('Directory error: {0}'.format(self.controller.job_dir))
            return

        for job_dir in job_dirs:
            abs_job_dir = os.path.join(self.controller.job_dir, job_dir)
            job_info_file = os.path.join(abs_job_dir, 'job_info.json')
            if os.path.exists(job_info_file):
                utils.info('Found job info file: {0}'.format(job_info_file))
                job_info = None
                try:
                    job_info = json.loads(open(job_info_file).read())
                except:
                    utils.error('Error parsing .json file')
                    return
                finally:
                    os.rename(job_info_file, '{0}.backup'.format(job_info_file))

                job_id = self.db.jobs.insert(
                    {'name'      : job_info['name'], 
                     'root'      : abs_job_dir,
                     'module'    : job_info['module'],
                     'status'    : 'active',
                     'params'    : job_info['module_data'],
                     'attempts'  : 0,
                     'fragments' : None,
                     'commands'  : []
                     })

                utils.info('Adding job: {0}'.format(job_info['name']))

                fragment_ids = self.create_fragments(job_id, job_info['module'])

                if fragment_ids is not None:
                    self.db.jobs.update({'_id' : job_id}, {'$set' : {'fragments' : fragment_ids}})
                else:
                    utils.error('Failed to creat fragments for {0}'.format(job_info['name']))
                    self.db.jobs.update({'_id' : job_id}, {'$set' : {'status' : 'failed'}})