Exemplo n.º 1
0
def get_rqinfo(options):
    """获取rq队列信息
    """
    redis_conn = Redis.from_url(options.connection)
    push_connection(redis_conn)
    # RQ队列信息获取操作
    if options.status:
        workers = Worker.all()
        queues = Queue.all()
        return workers, queues
    if options.queue:
        queue = Queue(options.queue)
        return queue
    if options.cancel_job:
        cancel_job(options.cancel_job)
        return 'OK'
    if options.requeue_job:
        requeue_job(options.requeue_job)
        return 'OK'
    if options.requeue_all:
        return requeue_all()
    if options.empty_queue:
        empty_queue(options.empty_queue)
        return 'OK'
    if options.compact_queue:
        compact_queue(options.compact_queue)
        return 'OK'
    if options.queues:
        return list_queues()
    if options.jobs:
        return list_jobs(options.jobs)
    if options.workers:
        return list_workers()
    pop_connection()
Exemplo n.º 2
0
Arquivo: worker.py Projeto: acs/arthur
    def perform_job(self, job, queue):
        """Custom method to execute a job and notify of its result

        :param job: Job object
        :param queue: the queue containing the object
        """

        result = super().perform_job(job, queue)

        job_status = job.get_status()
        job_result = job.return_value if job_status == 'finished' else None

        data = {
            'job_id': job.id,
            'status': job_status,
            'result': job_result
        }

        msg = pickle.dumps(data)
        self.connection.publish(CH_PUBSUB, msg)

        # Fixes the error #479 of RQ. Remove it as soon as it gets fixed.
        # (https://github.com/nvie/rq/issues/479)
        rq.pop_connection()

        return result
Exemplo n.º 3
0
def setup_redis():
    # Initialize Connection to Redis
    push_connection(Redis.from_url('redis://127.0.0.1:6379/2'))

    yield

    # Close connection to Redis
    pop_connection()
Exemplo n.º 4
0
def change_rq_instance(instance_number):
    redis_url = current_app.config.get("RQ_DASHBOARD_REDIS_URL")
    if not isinstance(redis_url, (list, tuple)):
        return dict(status="Single RQ. Not Permitted.")
    if int(instance_number) >= len(redis_url):
        raise LookupError("Index exceeds RQ list. Not Permitted.")
    pop_connection()
    _, current_app.redis_conn = from_url(redis_url[int(instance_number)])
    push_rq_connection()
    return dict(status="OK")
Exemplo n.º 5
0
def change_rq_instance(instance_number):
    redis_url = current_app.config.get('RQ_DASHBOARD_REDIS_URL')
    if not isinstance(redis_url, list):
        return dict(status='Single RQ. Not Permitted.')
    if int(instance_number) >= len(redis_url):
        raise LookupError('Index exceeds RQ list. Not Permitted.')
    pop_connection()
    current_app.redis_conn = from_url(redis_url[int(instance_number)])
    push_rq_connection()
    return dict(status='OK')
Exemplo n.º 6
0
def change_rq_instance(instance_number):
    redis_url = current_app.config.get('REDIS_URL')
    if not isinstance(redis_url, list):
        return dict(status='Single RQ. Not Permitted.')
    if int(instance_number) >= len(redis_url):
        raise LookupError('Index exceeds RQ list. Not Permitted.')
    pop_connection()
    current_app.redis_conn = from_url(redis_url[int(instance_number)])
    push_rq_connection()
    return dict(status='OK')
Exemplo n.º 7
0
    def tearDownClass(cls):
        logging.disable(logging.NOTSET)

        # Pop the connection to Redis
        testconn = pop_connection()
        assert testconn == cls.testconn, 'Wow, something really nasty ' \
                'happened to the Redis connection stack. Check your setup.'
Exemplo n.º 8
0
    def tearDownClass(cls):

        # Pop the connection to Redis
        testconn = pop_connection()
        assert testconn == cls.testconn, (
            "Wow, something really nasty " "happened to the Redis connection stack. Check your setup."
        )
Exemplo n.º 9
0
    def tearDownClass(cls):
        cls.log_handler.pop_thread()

        # Pop the connection to Redis
        testconn = pop_connection()
        assert testconn == cls.testconn, 'Wow, something really nasty ' \
                'happened to the Redis connection stack. Check your setup.'
Exemplo n.º 10
0
    def tearDownClass(cls):
        logging.disable(logging.NOTSET)

        # Pop the connection to Redis
        testconn = pop_connection()
        assert testconn == cls.testconn, 'Wow, something really nasty ' \
                'happened to the Redis connection stack. Check your setup.'
Exemplo n.º 11
0
    def tearDownClass(cls):
        cls.log_handler.pop_thread()

        # Pop the connection to Redis
        testconn = pop_connection()
        assert testconn == cls.testconn, 'Wow, something really nasty ' \
                'happened to the Redis connection stack. Check your setup.'
Exemplo n.º 12
0
def export_failed_jobs():
    """
    View function que retorna o CSV com os dados.
    Caso a fila esteja vazia, faz um redirect para a view "home" com
    uma mensagem flash, informativo.
    """

    redis_host = current_app.config['REDIS_HOST']
    redis_port = current_app.config['REDIS_PORT']
    redis_pass = current_app.config['REDIS_PASSWORD']
    con = Redis(host=redis_host, port=redis_port, password=redis_pass)
    push_connection(con)
    fq = get_failed_queue()
    fq_jobs = [serialize_job(job) for job in fq.get_jobs()]
    if fq.count > 0:
        dest = io.BytesIO()
        writer = csv.writer(dest)
        headers = [
            u'ID:',
            u'FILA:',
            u'PROCESSO:',
            u'TRACEBACK:',
        ]
        writer.writerow(headers)

        for job_data in fq_jobs:
            row_data = [
                job_data['id'],
                job_data['origin'],
                job_data['description'],
                job_data['exc_info'],
            ]
            writer.writerow(row_data)
        pop_connection()
        output = make_response(dest.getvalue())
        output.headers[
            "Content-Disposition"] = "attachment; filename=export_failed.csv"
        output.headers["Content-type"] = "text/csv"
        return output
    else:
        pop_connection()
        flash('A fila de falhas esta vazia!', 'warning')
        return redirect(url_for('home'))
Exemplo n.º 13
0
def export_failed_jobs():
    """
    View function que retorna o CSV com os dados.
    Caso a fila esteja vazia, faz um redirect para a view "home" com
    uma mensagem flash, informativo.
    """

    redis_host = current_app.config['REDIS_HOST']
    redis_port = current_app.config['REDIS_PORT']
    redis_pass = current_app.config['REDIS_PASSWORD']
    con = Redis(host=redis_host, port=redis_port, password=redis_pass)
    push_connection(con)
    fq = get_failed_queue()
    fq_jobs = [serialize_job(job) for job in fq.get_jobs()]
    if fq.count > 0:
        dest = io.BytesIO()
        writer = csv.writer(dest)
        headers = [
            u'ID:',
            u'FILA:',
            u'PROCESSO:',
            u'TRACEBACK:',
        ]
        writer.writerow(headers)

        for job_data in fq_jobs:
            row_data = [
                job_data['id'],
                job_data['origin'],
                job_data['description'],
                job_data['exc_info'],
            ]
            writer.writerow(row_data)
        pop_connection()
        output = make_response(dest.getvalue())
        output.headers["Content-Disposition"] = "attachment; filename=export_failed.csv"
        output.headers["Content-type"] = "text/csv"
        return output
    else:
        pop_connection()
        flash('A fila de falhas esta vazia!', 'warning')
        return redirect(url_for('home'))
Exemplo n.º 14
0
    def perform_job(self, job, queue):
        """Custom method to execute a job and notify of its result

        :param job: Job object
        :param queue: the queue containing the object
        """

        result = super().perform_job(job, queue)

        job_status = job.get_status()
        job_result = job.return_value if job_status == 'finished' else None

        data = {'job_id': job.id, 'status': job_status, 'result': job_result}

        msg = pickle.dumps(data)
        self.connection.publish(CH_PUBSUB, msg)

        # Fixes the error #479 of RQ. Remove it as soon as it gets fixed.
        # (https://github.com/nvie/rq/issues/479)
        rq.pop_connection()

        return result
def release_rq_connection(exception=None):
    pop_connection()
Exemplo n.º 16
0
 def tearDown(self):
     pop_connection()
Exemplo n.º 17
0
def pop_rq_connection(exception=None):
    pop_connection()
Exemplo n.º 18
0
    def tearDownClass(cls):
        logging.disable(logging.NOTSET)

        # Pop the connection to Redis,
        testconn = pop_connection()
        assert testconn == cls.testconn, 'Corrupted Redis connection stack'
Exemplo n.º 19
0
def teardown_module(module):
    logging.disable(logging.NOTSET)
    assert pop_connection() == conn
Exemplo n.º 20
0
def pop_rq_connection(exception=None):
    """Pop rq connection - view."""
    pop_connection()
Exemplo n.º 21
0
 def test_resolve_connection_raises_on_no_connection(self):
     """Test function resolve_connection raises if there is no connection."""
     pop_connection()
     with self.assertRaises(NoRedisConnectionException):
         Queue()
Exemplo n.º 22
0
 def tearDownClass(cls):
     conn = pop_connection()
     assert conn == cls.conn, \
         "Wow, something really nasty happened to the FakeRedis connection stack. Check your setup."
Exemplo n.º 23
0
def clear_rq_connection():
    while rq.pop_connection():
        pass
Exemplo n.º 24
0
def pop_rq_connection(execption=None):
    rq.pop_connection()
Exemplo n.º 25
0
 def test_resolve_connection_raises_on_no_connection(self):
     """Test function resolve_connection raises if there is no connection."""
     pop_connection()
     with self.assertRaises(NoRedisConnectionException):
         Queue()
def connection(request):
    push_connection(create_redis_connection('testing'))
    yield
    pop_connection()
Exemplo n.º 27
0
 def tearDown(self):
     pop_connection()
     self.get_redis_client().flushdb()
Exemplo n.º 28
0
Arquivo: base.py Projeto: acs/arthur
 def tearDownClass(cls):
     conn = pop_connection()
     assert conn == cls.conn, \
         "Wow, something really nasty happened to the FakeRedis connection stack. Check your setup."
Exemplo n.º 29
0
def pop_rq_connection(exception=None):
    pop_connection()
Exemplo n.º 30
0
 async def pop_rq_connection(request, response):
     pop_connection()