Beispiel #1
0
 def register(scanner, name, task_proxy):
     config = scanner.config
     registry = config.registry
     celery = get_celery(registry)
     celery_task = celery.task(task_proxy.original_func, *args,
                               **kwargs)
     proxy.bind_celery_task(celery_task)
Beispiel #2
0
def test_eager(celery_worker, task_app_request, dbsession, demo_user):
    """When in eager mode, transactions are executed properly.."""

    celery = get_celery(task_app_request.registry)
    celery._conf["task_always_eager"] = True

    try:

        # Try RetryableTransactionTask in eager mode
        with transaction.manager:
            # Do a dummy database write
            u = dbsession.query(User).first()

            demotasks.modify_username.apply_async(args=[u.id],
                                                  tm=transaction.manager)
            # Task should not execute until TM commits
            assert u.username != "set by celery"

        # TM commits the new result should be instantly available

        # Task has now fired after transaction was committed
        with transaction.manager:
            u = dbsession.query(User).first()
            assert u.username == "set by celery"

        # Let's test ScheduleOnCommitTask with manually managed transaction
        with transaction.manager:
            u = dbsession.query(User).first()
            u.username = "******"
            demotasks.modify_username_manual_transaction.apply_async(
                args=[u.id], tm=transaction.manager)

        # ScheduledOnCommitTask should have finished now
        with transaction.manager:
            u = dbsession.query(User).first()
            assert u.username == "set by celery"

    finally:
        celery._conf["task_always_eager"] = False
Beispiel #3
0
def test_eager(celery_worker, task_app_request, dbsession, demo_user):
    """When in eager mode, transactions are executed properly.."""

    celery = get_celery(task_app_request.registry)
    celery._conf["task_always_eager"] = True

    try:

        # Try RetryableTransactionTask in eager mode
        with transaction.manager:
            # Do a dummy database write
            u = dbsession.query(User).first()

            demotasks.modify_username.apply_async(args=[u.id], tm=transaction.manager)
            # Task should not execute until TM commits
            assert u.username != "set by celery"

        # TM commits the new result should be instantly available

        # Task has now fired after transaction was committed
        with transaction.manager:
            u = dbsession.query(User).first()
            assert u.username == "set by celery"

        # Let's test ScheduleOnCommitTask with manually managed transaction
        with transaction.manager:
            u = dbsession.query(User).first()
            u.username = "******"
            demotasks.modify_username_manual_transaction.apply_async(args=[u.id], tm=transaction.manager)

        # ScheduledOnCommitTask should have finished now
        with transaction.manager:
            u = dbsession.query(User).first()
            assert u.username == "set by celery"

    finally:
        celery._conf["task_always_eager"] = False
Beispiel #4
0
 def register(scanner, name, task_proxy):
     config = scanner.config
     registry = config.registry
     celery = get_celery(registry)
     celery_task = celery.task(task_proxy.original_func, *args, **kwargs)
     proxy.bind_celery_task(celery_task)