コード例 #1
0
    def geocode_to_model_instance(self, address, instance, commit=True):
        """
        Performs a geocoding and saves it to the instance that was passed in.
        It is expected that the instance inhertis from geocodemonkey.models.GeocodedObjectMixin
        """
        if not isinstance(instance, geo_model):
            raise TypeError("Instance argument is expected to be derived from geocodemonkey.models.GeocodedModel base class")

        # If this is an async Geocoder, we want to perform this asynchronously
        if self.ASYNC:
            from celery.app import Celery
            # Always commit on async
            celery = Celery()
            return celery.task(args=[self._geocode_to_model_instance(address, instance, commit=True)])
        else:
            return self._geocode_to_model_instance(address, instance, commit=commit)
コード例 #2
0
def _get_current_app():
    if default_app is None:
        #: creates the global fallback app instance.
        from celery.app import Celery
        set_default_app(Celery(
            'default', fixups=[], set_as_current=False,
            loader=os.environ.get('CELERY_LOADER') or 'default',
        ))
    return _tls.current_app or default_app
コード例 #3
0
def get_current_app():
    if default_app is None:
        #: creates the global fallback app instance.
        from celery.app import Celery, default_loader
        set_default_app(
            Celery('default',
                   loader=default_loader,
                   set_as_current=False,
                   accept_magic_kwargs=True))
    return _tls.current_app or default_app
コード例 #4
0
ファイル: _state.py プロジェクト: romand/celery
def get_current_app():
    if default_app is None:
        #: creates the global fallback app instance.
        from celery.app import Celery
        set_default_app(
            Celery('default',
                   loader=os.environ.get('CELERY_LOADER') or 'default',
                   set_as_current=False,
                   accept_magic_kwargs=True))
    return _tls.current_app or default_app
コード例 #5
0
    def geocode_to_model_instance(self, address, instance, commit=True):
        """
        Performs a geocoding and saves it to the instance that was passed in.
        It is expected that the instance inhertis from geocodemonkey.models.GeocodedObjectMixin
        """
        if not isinstance(instance, geo_model):
            raise TypeError(
                "Instance argument is expected to be derived from geocodemonkey.models.GeocodedModel base class"
            )

        # If this is an async Geocoder, we want to perform this asynchronously
        if self.ASYNC:
            from celery.app import Celery
            # Always commit on async
            celery = Celery()
            return celery.task(args=[
                self._geocode_to_model_instance(address, instance, commit=True)
            ])
        else:
            return self._geocode_to_model_instance(address,
                                                   instance,
                                                   commit=commit)
コード例 #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by ChenXin on 2017/8/8
from celery.app import Celery

app = Celery("celery_test", broker="redis://127.0.0.1:6379/0", backend="redis")
# app.connection("192.168.85.130")
from celery.signals import after_task_publish


@app.task
def add(x, y):
    return x + y


@after_task_publish.connect
def task_send_handler(sender=None, body=None, **kwargs):
    print kwargs
    print sender
    print body
    print('after_task_publis for task')

    # if __name__ == '__main__':
    #     app.start()
コード例 #7
0
from mediacrush.config import _cfg

from celery.app import Celery
from celery.utils.log import get_task_logger
from celery import chord, signature

redis_connection = "redis://%s:%s/1" % (_cfg("redis-ip"), _cfg("redis-port"))

app = Celery(
    "proj",
    broker=redis_connection,
    backend=redis_connection,
    include=["mediacrush.tasks"],
)

# Optional configuration, see the application user guide.
app.conf.update(
    CELERY_ACCEPT_CONTENT=["json"],
    CELERY_TASK_SERIALIZER="json",
    CELERY_RESULT_SERIALIZER="json",
    CELERY_CHORD_PROPAGATES=False,
    CELERY_ROUTES={"mediacrush.tasks.process_file": {
        "queue": "priority"
    }},
)

if __name__ == "__main__":
    app.start()
コード例 #8
0
from celery.app import Celery

import celeryconfig

celery_app = Celery(__name__, )

celery_app.config_from_object(celeryconfig)
コード例 #9
0
ファイル: t_util.py プロジェクト: yangjiu/phagescan
def _get_current_app(config_mod):
    current_app = Celery(config_source=config_mod,
                         include=config_mod.CELERY_IMPORTS,
                         tasks=config_mod.VALID_SCANNERS.tasks_no_install())
    return current_app
コード例 #10
0
from celery.app import Celery

from django.conf import settings

app = Celery('django_celery_example', broker=settings.CELERY_BROKER_URL)

app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

app.conf.update(
    result_backend=settings.CELERY_RESULT_BACKEND,
    beat_scheduler="django_celery_beat.schedulers:DatabaseScheduler",
    accept_content=['json'],
    task_serializer='json',
    result_serializer='json',
)
コード例 #11
0
ファイル: worker.py プロジェクト: fiziksis/player
"""
Main script for Celery worker.

"""
from __future__ import absolute_import

from celery.app import Celery

from cloudtunes import settings

celery = Celery('tasks',
                broker='redis://{host}:6379/1'.format(**settings.REDIS))

celery.conf.CELERY_DISABLE_RATE_LIMITS = True
celery.conf.CELERY_IMPORTS = [
    'cloudtunes.services.dropbox.sync',
    'cloudtunes.services.youtube.sync',
    'cloudtunes.services.facebook.sync',
    'cloudtunes.mail',
]


def main():
    celery.start()


if __name__ == '__main__':
    main()
コード例 #12
0
ファイル: celery_test.py プロジェクト: zqy1/antitools
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by ChenXin on 2017/8/8
from celery.app import Celery
app = Celery("celery_test",
             broker="amqp://*****:*****@192.168.85.130:5672/",
             backend="amqp")
# app.connection("192.168.85.130")


@app.task
def add(x, y):
    return x + y


#
if __name__ == '__main__':
    app.start()
    print app.__dict__
コード例 #13
0
import logging

from celery.app import Celery
from celery import shared_task

from sandbox import settings, Sandbox, UnsupportedLanguage, TimeoutError, MemoryLimitExceeded
from sandbox.settings import LANG_CONFIG

logging.basicConfig(
    filename='worker.log',
    level=logging.DEBUG,
    format='[%(asctime)s][%(name)s][%(levelname)s] %(message)s',
    datefmt='%m/%d/%Y %I:%M:%S %p',
)

celery = Celery('coderunner-sandbox')
celery.config_from_object(settings, namespace='CELERY')


@shared_task(name='tasks.sandbox.run_user_code')
def run_user_code(language, code, stdin):
    error, error_msg, output = False, None, None
    sandbox = None

    try:
        if language not in LANG_CONFIG:
            raise UnsupportedLanguage(f'{language} is not supported')
        sandbox = Sandbox()
        sandbox.run(language, code, stdin)
    except Exception as e:
        error = True