Beispiel #1
0
    def post(self, worker_uuid, state):
        worker = Worker.by_uuid(worker_uuid, self.db)

        if not worker:
            self.set_status(404, 'Unknown Worker')
            self.finish()
            return

        if 'start' == state:
            url = self.request.body
            if not url:
                logging.warning('Invalid URL trying to start worker %s.' % worker_uuid)
                raise tornado.web.HTTPError(400, 'Invalid URL', reason='Invalid URL')

            self.start_work(worker, url)
            return

        elif 'complete' == state and worker.current_url is not None:
            self.complete_work(worker, worker.current_url)
            worker.current_url = None

        else:
            logging.warning('Invalid operation (not start nor complete) in worker %s (current url: %s).' % (
                worker_uuid, worker.current_url
            ))
Beispiel #2
0
    def post(self, worker_uuid, i_am='alive'):
        self._remove_zombie_workers()

        worker = Worker.by_uuid(worker_uuid, self.db)

        if worker:
            if i_am == 'alive':
                worker.last_ping = datetime.now()
            elif i_am == 'dead':
                self.db.delete(worker)
        else:
            worker = Worker(uuid=worker_uuid)
            self.db.add(worker)

        self.db.flush()

        self.application.event_bus.publish(dumps({
            'type': 'worker-status',
            'workerId': str(worker.uuid)
        }))

        self.write(str(worker_uuid))