当前位置: 首页>>代码示例>>Python>>正文


Python celery.shared_task方法代码示例

本文整理汇总了Python中celery.shared_task方法的典型用法代码示例。如果您正苦于以下问题:Python celery.shared_task方法的具体用法?Python celery.shared_task怎么用?Python celery.shared_task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在celery的用法示例。


在下文中一共展示了celery.shared_task方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: task

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def task(*d_args, **d_kwargs):
    # behaves like @task, but emails about exceptions.
    def real_decorator(f):
        @shared_task(*d_args, **d_kwargs)
        @wraps(f)
        def wrapper(*f_args, **f_kwargs):
            # try the task; email any exceptions we get
            try:
                res = f(*f_args, **f_kwargs)
            except Exception as e:
                # email admins and re-raise
                exc_type, exc_value, exc_traceback = sys.exc_info()
                subject = 'task failure in %s.%s' % (f.__module__, f.__name__)
                msg = 'The task %s.%s failed:\n\n%s' % (f.__module__, f.__name__,
                        '\n'.join(traceback.format_exception(exc_type, exc_value, exc_traceback)))
                mail_admins(subject=subject, message=msg, fail_silently=True)
                raise

            return res
        return wrapper
    return real_decorator 
开发者ID:sfu-fas,项目名称:coursys,代码行数:23,代码来源:celerytasks.py

示例2: shared_task_conditional

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def shared_task_conditional(**kwargs):  # pragma: no cover
    """Decorator to optionally disable celery tests."""
    def decorator(func):
        if settings.NO_CELERY:
            setattr(func, 'delay', func)
            return func

        # Get the real decorator
        dec = shared_task(func, **kwargs)

        # Create a stub to apply a countdown and run
        def patched(*args, **kwargs):
            return dec.apply_async(
                args=args, kwargs=kwargs, countdown=settings.CELERY_DELAY)

        # Substitute the delay method
        dec.delay = patched
        return dec

    return decorator 
开发者ID:wncc,项目名称:instiapp-api,代码行数:22,代码来源:celery.py

示例3: test_shared_task

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def test_shared_task(celery_app, memory_exporter):
    """Ensure Django Shared Task are supported"""

    @celery.shared_task
    def add(x, y):
        return x + y

    result = add.apply([2, 2])
    assert result.result == 4

    spans = memory_exporter.get_finished_spans()
    assert len(spans) == 1

    span = spans[0]

    assert span.status.is_ok is True
    assert span.name == "test_celery_functional.add"
    assert (
        span.attributes.get("celery.task_name") == "test_celery_functional.add"
    )
    assert span.attributes.get("celery.action") == "run"
    assert span.attributes.get("celery.state") == "SUCCESS"
    assert span.attributes.get("messaging.message_id") == result.task_id 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:25,代码来源:test_celery_functional.py

示例4: shared_task

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def shared_task(task):  # noqa: D103, pylint: disable=missing-docstring
        return task 
开发者ID:genialis,项目名称:resolwe,代码行数:4,代码来源:tasks.py

示例5: task

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def task(self):
        return shared_task(**self.config)(self._run_task)


# Define tasks so that Celery can discovery them 
开发者ID:desec-io,项目名称:desec-stack,代码行数:7,代码来源:mail_backends.py

示例6: shared_task

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def shared_task(func):
        def wrapper(*args, **kwargs):
            return func(*args, **kwargs)
        return wrapper 
开发者ID:bitlabstudio,项目名称:django-influxdb-metrics,代码行数:6,代码来源:tasks.py

示例7: _create_db_asset

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def _create_db_asset(fcn, model, args, key):
    if getattr(settings, 'LEDGER_SYNC_ENABLED', True):
        return __create_db_asset(model, fcn, args, key, sync=True)
    else:
        shared_task(__create_db_asset)(model, fcn, args, key, sync=False)
        return {'message': _MESSAGE} 
开发者ID:SubstraFoundation,项目名称:substra-backend,代码行数:8,代码来源:ledger.py

示例8: _create_db_assets

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def _create_db_assets(fcn, model, args, keys):
    if getattr(settings, 'LEDGER_SYNC_ENABLED', True):
        return __create_db_assets(model, fcn, args, keys, sync=True)
    else:
        shared_task(__create_db_asset)(model, fcn, args, keys, sync=False)
        return {'message': _MESSAGE} 
开发者ID:SubstraFoundation,项目名称:substra-backend,代码行数:8,代码来源:ledger.py

示例9: __create_asset

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def __create_asset(fcn, args, sync=False, **extra_kwargs):
    # create a wrapper as it seems the shared_task decorator from celery is not
    # compatible with our retry decorator on the invoke_ledger function
    return invoke_ledger(fcn=fcn, args=args, sync=sync, **extra_kwargs) 
开发者ID:SubstraFoundation,项目名称:substra-backend,代码行数:6,代码来源:ledger.py

示例10: _create_asset

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def _create_asset(fcn, args, **extra_kwargs):
    if getattr(settings, 'LEDGER_SYNC_ENABLED', True):
        return __create_asset(fcn, args=args, sync=True, **extra_kwargs)
    else:
        shared_task(__create_asset)(fcn, args=args, sync=False, **extra_kwargs)
        return {'message': _MESSAGE} 
开发者ID:SubstraFoundation,项目名称:substra-backend,代码行数:8,代码来源:ledger.py

示例11: configure_worker

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def configure_worker(options={}, **kwargs):

    if 'queues' not in options:
        return
    if CORRESPONDING_QUEUE not in options['queues'].split(','):
        return
    print('### STARTING UP A TREE BUILDER WORKER ###')

    global retroTransformer
    # Instantiate and load retro transformer
    retroTransformer = RetroTransformer(celery=True)
    retroTransformer.load(chiral=False)

    print('### TREE BUILDER WORKER STARTED UP ###')


# ONLY ONE WORKER TYPE HAS THIS FUNCTION EXPOSED - MAKE IT THE CHIRAL ONE
# @shared_task
# def fast_filter_check(*args, **kwargs):
#     '''Wrapper for fast filter check, since these workers will 
#     have it initialized. Best way to allow independent queries'''
#     global retroTransformer
#     if not retroTransformer.fast_filter:
#         from makeit.synthetic.evaluation.fast_filter import FastFilterScorer
#         retroTransformer.fast_filter = FastFilterScorer()
#         retroTransformer.fast_filter.load(model_path=gc.FAST_FILTER_MODEL['trained_model_path'])
#     return retroTransformer.fast_filter.evaluate(*args, **kwargs) 
开发者ID:connorcoley,项目名称:ASKCOS,代码行数:29,代码来源:tb_worker.py

示例12: shared_task

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def shared_task(func):
        # Dummy decorator so that we can use the decorator wether celery is installed or not

        # We do not yet need this, but might come in handy in the future:
        #func.delay = lambda *a, **kw: func(*a, **kw)
        #func.apply_async = lambda *a, **kw: func(*a, **kw)
        return func 
开发者ID:mathiasertl,项目名称:django-ca,代码行数:9,代码来源:tasks.py

示例13: mutex_task

# 需要导入模块: import celery [as 别名]
# 或者: from celery import shared_task [as 别名]
def mutex_task(task_id_template=None, **shared_task_kwargs):
    """ Wraps a task that must be executed only once.

    :param task_id_template: String that makes unique task IDs from passed args
        (If omitted, we just use the function name)
    :param shared_task_kwargs: Passed through to `shared_task`
    """

    def decorator(func):
        signature = inspect.signature(func)

        @shared_task(**shared_task_kwargs, bind=True)
        @wraps(func)
        def wrapped_task(self, *task_args, **task_kwargs):
            if task_id_template:
                passed_args = signature.bind(*task_args, **task_kwargs)
                passed_args.apply_defaults()
                task_identifier = task_id_template.format_map(passed_args.arguments)
            else:
                task_identifier = func.__name__

            with exclusive_lock(task_identifier) as has_lock:
                if has_lock:
                    return func(*task_args, **task_kwargs)
                logger.debug("Other worker already processing %s", task_identifier)
            return None

        return wrapped_task

    return decorator 
开发者ID:DavidCain,项目名称:mitoc-trips,代码行数:32,代码来源:tasks.py


注:本文中的celery.shared_task方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。