Esempio n. 1
0
    def handle(self, *args, **kwargs):
        global MANAGER_ON
        MANAGER_ON = True

        print 'Starting Up...'

        if kwargs['verbose']: log_verbose()

        log_manager_start()

        workers = Workers(
            kwargs['worker'],
            kwargs['jobs'],
            kwargs['timeout'],
        )

        try:

            while MANAGER_ON:
                workers.pull()
                time.sleep(1)
                workers.check()
                time.sleep(1)
                workers.poll()
                time.sleep(1)
                if kwargs['test']:
                    MANAGER_ON = False

        except KeyboardInterrupt:
            MANAGER_ON = False
        except Exception, e:
            log_manager_error(traceback.format_exc())
Esempio n. 2
0
    def pull(self):
        self.lock_thread.acquire()

        # get jobs for this worker
        jobs_all, jobs_new = worker_pull(self.uid, jobs=self.available())

        # remove all lost jobs from ping
        jobs_remove = []
        last_job = len(self.jobs)
        while last_job > 0:
            last_job -= 1
            if self.jobs[last_job]['recipe']['setup']['uuid'] not in jobs_all:
                jobs_remove.append(self.jobs[last_job])
                del self.jobs[last_job]

        # add all new jobs to ping
        self.jobs.extend(jobs_new)

        # allow pings to resume with up to date list
        self.lock_thread.release()

        # shut down all removed jobs
        try:
            for job in jobs_remove:
                if job.get('job', {}).get('process'):
                    job['job']['process'].kill()
                self.cleanup(job)
                log_job_cancel(job)
        except Exception as e:
            log_manager_error(traceback.format_exc())
Esempio n. 3
0
 def ping(self):
     # update all jobs belonging to worker
     while not self.ping_event.wait(JOB_INTERVAL_MS / 1000):
         self.lock_thread.acquire()
         try:
             worker_ping(
                 self.uid,
                 [job['recipe']['setup']['uuid'] for job in self.jobs])
         except Exception as e:
             log_manager_error(traceback.format_exc())
         self.lock_thread.release()
Esempio n. 4
0
 def check(self):
     self.lock_thread.acquire()
     try:
         recipes = worker_check(self.uid)
         last_job = len(self.jobs) - 1
         while last_job >= 0:
             if self.jobs[last_job]['recipe']['setup'][
                     'uuid'] not in recipes:
                 self.jobs[last_job]['job']['process'].kill()
                 self.cleanup(self.jobs[last_job])
                 log_job_cancel(self.jobs[last_job])
                 del self.jobs[last_job]
             last_job -= 1
     except Exception, e:
         log_manager_error(traceback.format_exc())
Esempio n. 5
0
    def handle(self, *args, **kwargs):
        global MANAGER_ON
        MANAGER_ON = True

        print('Starting Up...')

        if kwargs['verbose']: log_verbose()

        log_manager_start()

        workers = Workers(
            kwargs['worker'],
            kwargs['jobs'],
            kwargs['timeout'],
            kwargs['trace'],
        )

        try:

            while MANAGER_ON:
                workers.pull()
                time.sleep(JOB_INTERVAL_MS / 1000)
                workers.poll()
                time.sleep(JOB_INTERVAL_MS / 1000)
                if kwargs['test']:
                    MANAGER_ON = False

        except KeyboardInterrupt:
            MANAGER_ON = False
        except Exception as e:
            log_manager_error(traceback.format_exc())

        print('Shutting Down...')
        workers.shutdown()

        log_manager_end()