Пример #1
0
def stats(arguments):
    control = Control(app=airflow.app.celery)

    nodename = f"celery@{airflow.utils.get_hostname()}"

    logging.info("Getting node stats")
    logging.info(control.broadcast("stats", reply=True,
                                   destination=[nodename]))

    logging.info("Getting active queues")
    logging.info(
        control.broadcast("active_queues", reply=True, destination=[nodename]))

    logging.info("Getting active tasks")
    logging.info(
        control.broadcast("active", reply=True, destination=[nodename]))
Пример #2
0
class WorkerShutdownHandler(object):
    def __init__(self, worker):
        self.worker = worker
        self.nodename = worker.hostname
        self.app = worker.app

        self.control = Control(app=self.app)

    def __call__(self, *args):
        print(f"Status of: {self.nodename}")
        with self.app.connection_for_read() as connection:
            print(self.control.broadcast("stats",
                connection=connection,
                destination=[self.nodename],
                reply=True
            ))

        print(f"Consumers closed for: {self.nodename}")
        self.halt()
        print(f"Marking tasks failed under: {self.nodename}")
        self.terminate()

    def halt(self):
        with self.app.connection_for_read() as connection:
            result = self.control.broadcast("active_queues",
                connection=connection,
                destination=[self.nodename],
                reply=True
            )

            print(result)

            result = self.control.broadcast("active",
                connection=connection,
                destination=[self.nodename],
                reply=True
            )

            print(result)

        # self.worker.pool.stop()

    def terminate(self):
        print("******************")
Пример #3
0
def worker_abort(arguments):
    nodename = f"celery@{airflow.utils.get_hostname()}"

    control = Control(app=airflow.app.celery)
    results = control.broadcast("stats", reply=True, destination=[nodename])

    proc_id = results[0][nodename]["pid"]

    logging.info("Sending SIGABRT (%s) to worker process ID: %s",
                 Signals.SIGABRT, proc_id)
    os.kill(proc_id, Signals.SIGABRT)