Пример #1
0
def test_factory_pattern(app, config):
    rq = RQ(default_timeout=111)
    rq.init_app(app)

    # override some rq defaults
    rq.default_timeout = 222
    rq.default_result_ttl = 333
    rq.default_queue = 'non-default'
    rq.job(add)

    # then check if those default have been passed to the helper
    assert add.helper.timeout == 222
    assert add.helper.result_ttl == 333
    assert add.helper.queue_name == 'non-default'

    # then queue if the values have been passed to the job as well
    job = add.queue(1, 2)
    assert job.timeout == 222
    assert job.result_ttl == 333
    assert job.ttl is None
    assert job.origin == 'non-default'

    # change the values in the helpr and see if that works
    add.helper.timeout = 444
    assert add.helper.timeout == 444
    add.helper.result_ttl = 555
    assert add.helper.result_ttl == 555
    add.helper.queue_name = 'totally-different'
    assert add.helper.queue_name == 'totally-different'

    # assert the helper's values
    job = add.queue(1, 2)
    assert job.timeout == 444
    assert job.result_ttl == 555
    assert job.ttl is None
    assert job.origin == 'totally-different'

    # now finally override the values while queueing
    job = add.queue(1,
                    2,
                    queue='yet-another',
                    timeout=666,
                    result_ttl=777,
                    ttl=888)
    assert job.timeout == 666
    assert job.result_ttl == 777
    assert job.ttl == 888
    assert job.origin == 'yet-another'
Пример #2
0
def test_factory_pattern(app, config):
    rq = RQ(default_timeout=111)
    rq.init_app(app)

    # override some rq defaults
    rq.default_timeout = 222
    rq.default_result_ttl = 333
    rq.default_queue = 'non-default'
    rq.job(add)

    # then check if those default have been passed to the helper
    assert add.helper.timeout == 222
    assert add.helper.result_ttl == 333
    assert add.helper.queue_name == 'non-default'

    # then queue if the values have been passed to the job as well
    job = add.queue(1, 2)
    assert job.timeout == 222
    assert job.result_ttl == 333
    assert job.ttl is None
    assert job.origin == 'non-default'

    # change the values in the helpr and see if that works
    add.helper.timeout = 444
    assert add.helper.timeout == 444
    add.helper.result_ttl = 555
    assert add.helper.result_ttl == 555
    add.helper.queue_name = 'totally-different'
    assert add.helper.queue_name == 'totally-different'

    # assert the helper's values
    job = add.queue(1, 2)
    assert job.timeout == 444
    assert job.result_ttl == 555
    assert job.ttl is None
    assert job.origin == 'totally-different'

    # now finally override the values while queueing
    job = add.queue(1, 2,
                    queue='yet-another', timeout=666, result_ttl=777, ttl=888)
    assert job.timeout == 666
    assert job.result_ttl == 777
    assert job.ttl == 888
    assert job.origin == 'yet-another'
Пример #3
0
from mpcontribs.api import get_kernel_endpoint, get_logger
from mpcontribs.api.core import SwaggerView
from mpcontribs.api.contributions.document import Contributions
from mpcontribs.api.notebooks.document import Notebooks
from mpcontribs.api.notebooks import run_cells

logger = get_logger(__name__)
templates = os.path.join(os.path.dirname(flask_mongorest.__file__),
                         "templates")
notebooks = Blueprint("notebooks", __name__, template_folder=templates)

MPCONTRIBS_API_HOST = os.environ["MPCONTRIBS_API_HOST"]
ADMIN_GROUP = os.environ.get("ADMIN_GROUP", "admin")

rq = RQ()
rq.default_queue = f"notebooks_{MPCONTRIBS_API_HOST}"
rq.queues = [rq.default_queue]
rq.scheduler_queue = rq.default_queue
rq.scheduler_class = "mpcontribs.api.notebooks.views.NotebooksScheduler"


class NotebooksScheduler(Scheduler):
    redis_scheduler_namespace_prefix = f'rq:scheduler_instance:{MPCONTRIBS_API_HOST}:'
    scheduler_key = f'rq:scheduler:{MPCONTRIBS_API_HOST}'
    scheduler_lock_key = f'rq:scheduler_lock:{MPCONTRIBS_API_HOST}'
    scheduled_jobs_key = f'rq:scheduler:scheduled_jobs:{MPCONTRIBS_API_HOST}'


class NotebooksResource(Resource):
    document = Notebooks
    filters = {"id": [ops.In, ops.Exact]}