How to use the celery.shared_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 seanbell / opensurfaces / server / photos / tasks.py View on Github external
@shared_task
def detect_vanishing_points(photo_id, dim=800):
    """ Detects vanishing points for a photo and stores it in the database in
    the photo model. """

    # load photo
    photo = Photo.objects.get(id=photo_id)
    orig_image = open_image(photo.image_2048)

    old_vanishing_lines = photo.vanishing_lines
    old_vanishing_points = photo.vanishing_points
    old_vanishing_length = photo.vanishing_length

    detect_vanishing_points_impl(
        photo, ResizeToFit(dim, dim).process(orig_image),
        save=False)
github VirtualJudge / VirtualJudge / utils / tasks.py View on Github external
@shared_task
def hook_task(submission_id):
    try:
        if len(Submission.objects.filter(id=submission_id)):
            submission = Submission.objects.get(id=submission_id)
            user_profile = UserProfile.objects.get(username=submission.user)
            if user_profile.hook is not None:
                req = utils.HttpUtil()
                req.post(url=user_profile.hook, json=VerdictSerializer(submission).data)
            submission.hook = True
            submission.save()
            user_profile.hook_times += 1
            user_profile.save()
    except DatabaseError:
        pass
github nephila / django-maja-newsletter / maja_newsletter / tasks.py View on Github external
@shared_task
def export_excel(data, recipient, export_name=None, headers=None, force_csv=False, encoding='utf8'):
    filedir = mkdtemp()
    output_file = os.path.join(filedir, export_name)
    with open(output_file, 'wb') as output:
        output, mimetype, file_ext = make_excel_content(data, output, headers, force_csv, encoding)
    final_path = '{0}.{1}'.format(output_file, file_ext)
    shutil.copyfile(output_file, final_path)
    testo = EXPORT_FILE_NAME
    message = EmailMessage(EXPORT_EMAIL_SUBJECT, testo, settings.DEFAULT_FROM_EMAIL, [recipient])
    message.attach_file(final_path, mimetype=mimetype)
    message.send()
    shutil.rmtree(filedir)
github La0 / coach / plan / tasks.py View on Github external
@shared_task
def athletes_daily_sessions():
  '''
  For all trainers, send a daily email
  with sessions about to be done today
  '''
  from django.utils.translation import ugettext_lazy as _
  from club.models import ClubMembership
  from sport.models import SportSession
  from coach.mail import MailBuilder
  from datetime import date

  today = date.today()
  memberships = ClubMembership.objects.filter(role='trainer', user__daily_trainer_mail=True)
  for m in memberships:
    # List athletes sessions for today
    users = [cm.user for cm in m.athletes]
github SoftwareHeritage / swh-lister / swh / lister / phabricator / tasks.py View on Github external
@shared_task(name=__name__ + ".FullPhabricatorLister")
def list_phabricator_full(**lister_args):
    """Full update of a Phabricator instance"""
    return PhabricatorLister(**lister_args).run()
github ofa / everyvoter / rendering / tasks.py View on Github external
@shared_task
def sample_email(to_address, user_id, email_id, election_id, district_ids):
    """Sample an email to an end user"""
    result = compose_email(
        user_id,
        email_id,
        election_id,
        district_ids)

    newrelic.agent.add_custom_parameter(
        'organization_id', result['organization_id'])
    newrelic.agent.add_custom_parameter(
        'email_id', result['email_id'])

    final_subject = u'[sample] {}'.format(result['subject'])

    deliver(
github harvard-lil / perma / perma_web / perma / tasks.py View on Github external
@shared_task(bind=True)
def upload_to_internet_archive(self, link_guid):
    try:
        link = Link.objects.get(guid=link_guid)

        if link.internet_archive_upload_status == 'failed_permanently':
            return

    except:
        print "Link %s does not exist" % link_guid
        return

    if not settings.UPLOAD_TO_INTERNET_ARCHIVE:
        return

    if not link.can_upload_to_internet_archive():
        print "Not eligible for upload."
github mozilla / mozillians / mozillians / users / tasks.py View on Github external
@shared_task(bind=True, base=DebugBasketTask, default_retry_delay=BASKET_TASK_RETRY_DELAY,
             max_retries=BASKET_TASK_MAX_RETRIES)
def lookup_user_task(self, email):
    """Task responsible for getting information about a user in basket."""

    # We need to return always a dictionary for the next task
    result = {}

    try:
        result = basket.lookup_user(email=email)
    except MaxRetriesExceededError as exc:
        raise exc
    except basket.BasketException as exc:
        if not exc[0] == u'User not found':
            raise self.retry(exc=exc)
        result = exc.result
    return result
github JBEI / edd / edd / remote_tasks.py View on Github external
@shared_task(bind=True)
def debug_task(self):
    logger.info('Request: {0!r}'.format(self.request))
github Rustem / toptal-blog-celery-toy-ex / celery_uncovered / toyex / tasks.py View on Github external
@shared_task
def report_error_task(subject, message, *args, **kwargs):
    mail_admins(subject, message, *args, **kwargs)