How to use the celery.task function in celery

To help you get started, we’ve selected a few celery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cameronmaske / celery-once / tests / unit / test_tasks.py View on Github external
@task(name='simple_example', base=QueueOnce)
def simple_example():
    return "simple"
github groveco / django-sprinklers / sample / sprinkle_actions.py View on Github external
@task
def run_sample_sprinkle(**kwargs):
    SampleSprinkle.create_sprinkles(**kwargs)
github sv1jsb / dwitter / dwitter / main / tasks.py View on Github external
@task
def celery_send_mail(subject, message, from_email, to_email):
    send_mail(subject, message, from_email, [to_email])
github churchlab / millstone / genome_designer / genome_finish / assembly_runner.py View on Github external
@task
def _chordfinisher(*args, **kwargs):
    """
    Needs to run at the end of a chord to delay the variant parsing step.

    http://stackoverflow.com/questions/
    15123772/celery-chaining-groups-and-subtasks-out-of-order-execution
    """
    return "FINISHED VARIANT FINDING."
github openstate / open-cultuur-data / ocd_frontend / rest / tasks.py View on Github external
@celery.task(ignore_result=True)
def log_event(user_agent, referer, user_ip, created_at, event_type, **kwargs):
    """Log user activity events to the specified 'usage logging'
    ElasticSearch index.

    :param user_agent: the user's raw user agent string
    :type user_agent: str
    :param referer: the contents of the HTTP referer request header
    :type referer: str or None
    :param user_ip: the user's IP address
    :type user_ip: str
    :param crated_at: the datetime when the event was created (in UTC)
    :type created_at: datetime.datetime
    :event_type: the name of the event type; available event types are
                 specified under ``available_event_types``
    :param kwargs: any additional arguments will be passed on to the
                   function responsible for processing the event
github AustralianSynchrotron / lightflow / lightflow / queue / jobs.py View on Github external
@celery.task(bind=True)
def execute_task(self, task, workflow_id, data=None):
    """ Celery task that runs a single task on a worker.

    Args:
        self (Task): Reference to itself, the celery task object.
        task (BaseTask): Reference to the task object that performs the work
                         in its run() method.
        workflow_id (string): The unique ID of the workflow run that started this task.
        data (MultiTaskData): An optional MultiTaskData object that contains the data
                              that has been passed down from upstream tasks.
    """
    start_time = datetime.utcnow()

    store_doc = DataStore(**self.app.user_options['config'].data_store,
                          auto_connect=True).get(workflow_id)
    store_loc = 'log.{}.tasks.{}'.format(task.dag_name, task.name)
github mozilla / kitsune / kitsune / notifications / tasks.py View on Github external
@task(ignore_result=True)
def add_notification_for_action(action_id):
    action = Action.objects.get(id=action_id)
    query = _full_ct_query(action, actor_only=False)
    # Don't send notifications to a user about actions they take.
    query &= ~Q(user=action.actor)

    # execute the above query, iterate through the results, get every user
    # assocated with those Follow objects, and fire off a notification to
    # every one of them. Use a set to only notify each user once.
    users_to_notify = set(f.user for f in Follow.objects.filter(query))
    # Don't use bulk save since that wouldn't trigger signal handlers
    for u in users_to_notify:
        Notification.objects.create(owner=u, action=action)
github pulp / pulpcore / server / pulp / server / managers / consumer / group / cud.py View on Github external
errors.append(e)
            except Exception, e:
                _logger.exception(e)
                errors.append(e)
                # Don't do anything else since we still want to process all the other consumers

        error = None
        if len(errors) > 0:
            error = PulpCodedException(error_code, **error_kwargs)
            error.child_exceptions = errors
        return TaskResult({}, error, spawned_tasks)


associate = task(ConsumerGroupManager.associate, base=Task, ignore_result=True)
create_consumer_group = task(ConsumerGroupManager.create_consumer_group, base=Task)
delete_consumer_group = task(ConsumerGroupManager.delete_consumer_group, base=Task,
                             ignore_result=True)
update_consumer_group = task(ConsumerGroupManager.update_consumer_group, base=Task)
unassociate = task(ConsumerGroupManager.unassociate, base=Task, ignore_result=True)
bind = task(ConsumerGroupManager.bind, base=Task)
unbind = task(ConsumerGroupManager.unbind, base=Task)


def validate_existing_consumer_group(group_id):
    """
    Validate the existence of a consumer group, given its id.
    Returns the consumer group db collection upon successful validation,
    raises an exception upon failure
    @param group_id: unique id of the consumer group to validate
    @type  group_id: str
    @return: consumer group db collection
    @rtype:  L{pulp.server.db.connection.PulpCollection}
github pulp / pulp / server / pulp / server / managers / content / orphan.py View on Github external
Exceptions are logged and discarded.
        :param path: An absolute path.
        :type path: str
        """
        try:
            if os.path.isfile(path) or os.path.islink(path):
                os.unlink(path)
            else:
                shutil.rmtree(path)
        except OSError, e:
            _logger.error(_('Delete path: %(p)s failed: %(m)s'), {'p': path, 'm': str(e)})


delete_all_orphans = task(OrphanManager.delete_all_orphans, base=Task)
delete_orphans_by_id = task(OrphanManager.delete_orphans_by_id, base=Task, ignore_result=True)
delete_orphans_by_type = task(OrphanManager.delete_orphans_by_type, base=Task, ignore_result=True)
github mdn / kuma / kuma / wiki / tasks.py View on Github external
@task
def build_locale_sitemap(locale):
    """
    For the given locale build the appropriate sitemap file and
    returns the locale, the file names written and timestamp of the
    build.
    """
    now = datetime.utcnow()
    timestamp = '%s+00:00' % now.replace(microsecond=0).isoformat()

    directory = os.path.join(settings.MEDIA_ROOT, 'sitemaps', locale)
    if not os.path.isdir(directory):
        os.makedirs(directory)

    # Add any non-document URL's, which will always include the home page.
    other_urls = [
        {