Ejemplo n.º 1
0
 def __call__(self):
     app = Application(self.config, self.log_level)
     app.logger.info(
         "fastlane is runnning.",
         host=self.host,
         port=self.port,
         environment=self.config.ENV,
     )
     app.run(self.host, self.port)
Ejemplo n.º 2
0
def client():
    conf = Config.load(ROOT_CONFIG)
    app = Application(conf, log_level="ERROR", testing=True)
    app.config["TESTING"] = True
    client = app.app.test_client()
    client.application.redis.flushall()

    Task.objects.delete()

    yield client
Ejemplo n.º 3
0
def auth_client():
    conf = Config.load(ROOT_CONFIG)
    conf.BASIC_AUTH_USERNAME = "******"
    conf.BASIC_AUTH_PASSWORD = "******"
    app = Application(conf, log_level="ERROR", testing=True)
    app.config["TESTING"] = True
    cli = app.app.test_client()
    cli.application.redis.flushall()

    Task.objects.delete()
    Job.objects.delete()

    yield cli
Ejemplo n.º 4
0
    def __call__(self):
        # self.click.echo(
        # f'Running fastlane worker processing queues {",".join(self.queues)}.')
        app = Application(self.config, self.log_level)
        app.logger.info(
            f'Running fastlane worker processing queues {",".join(self.queues)}.'
        )
        interval = app.config["WORKER_SLEEP_TIME_MS"] / 1000.0

        with app.app.app_context():
            worker_kw = dict(connection=app.app.redis)

            if self.worker_id is None:
                app.logger.warn(
                    "The worker id was not set for this worker and a random one will be used."
                )
                self.worker_id = str(uuid4())

            app.logger = app.logger.bind(worker_id=self.worker_id,
                                         queues=self.queues)
            app.app.logger = app.logger
            worker_kw["name"] = self.worker_id

            worker = Worker(self.queues, **worker_kw)

            schedulers = {}

            with Connection(app.app.redis):
                for queue in self.queues:
                    schedulers[queue] = QueueScheduler(queue, app=app.app)
                app.schedulers = schedulers

                # app.logger.debug('Processing enqueued items...')

                try:
                    while True:
                        for queue in self.queues:
                            # app.logger.debug("Processing scheduler...", queue=queue)
                            schedulers[queue].move_jobs()

                        # app.logger.debug('Processing queues...')
                        worker.work(burst=True)
                        enqueue_missing_monitor_jobs(app.app)
                        time.sleep(interval)
                except rq.worker.StopRequested:
                    app.logger.info("Worker exiting gracefully.")

                    return
Ejemplo n.º 5
0
    def __call__(self):
        # self.click.echo(
        # f'Running fastlane worker processing queues {",".join(self.queues)}.')
        self.app = app = Application(self.config, self.log_level)
        self.queue_group = self.app.app.queue_group

        app.logger.info(
            f'Running fastlane worker processing queues {",".join(self.queues)}.'
        )
        interval = app.config["WORKER_SLEEP_TIME_MS"] / 1000.0
        self.last_verified_missing_jobs = time.time()

        with app.app.app_context():
            if self.worker_id is None:
                app.logger.warn(
                    "The worker id was not set for this worker and a random one will be used."
                )
                self.worker_id = str(uuid4())

            app.logger = app.logger.bind(worker_id=self.worker_id,
                                         queues=self.queues)
            app.app.logger = app.logger

            while True:
                try:
                    self.loop_once()
                    time.sleep(interval)
                except Exception:
                    error = traceback.format_exc()
                    app.logger.error("Failed to process job.", error=error)
Ejemplo n.º 6
0
def worker():
    conf = Config.load(ROOT_CONFIG)
    app = Application(conf, log_level="ERROR", testing=True)
    app.config["TESTING"] = True
    cli = app.app.test_client()
    cli.application.redis.flushall()

    Task.objects.delete()
    Job.objects.delete()

    worker_instance = WorkerHandler(None,
                                    str(uuid4()),
                                    True,
                                    True,
                                    True,
                                    True,
                                    app.config,
                                    0,
                                    app=app)

    yield worker_instance
Ejemplo n.º 7
0
 def __call__(self):
     app = Application(self.config, self.log_level).app
     app.logger.info(f"Running fastlane prune...")
     with app.app_context():
         removed = app.executor.remove_done()
         app.logger.info(f"Prune done.", removed=removed)