Move task so celery will register it (bug 693828)

This commit is contained in:
Rob Hudson 2011-10-11 16:09:39 -07:00
Родитель b40d450d4d
Коммит bfd2e2a5a3
3 изменённых файлов: 39 добавлений и 48 удалений

Просмотреть файл

@ -1,41 +0,0 @@
from datetime import date
import urllib2
from django.conf import settings
from django.utils.http import urlencode
from celery.decorators import task
def make_source_url(request):
"""Responsys expects the URL in the format example.com/foo."""
return request.get_host() + request.get_full_path()
@task
def subscribe(campaign, address, format='html', source_url='',
lang='', country=''):
"""
Subscribe a user to a list in responsys. There should be two
fields within the Responsys system named by the "campaign"
parameter: <campaign>_FLG and <campaign>_DATE.
"""
data = {
'LANG_LOCALE': lang,
'COUNTRY_': country,
'SOURCE_URL': source_url,
'EMAIL_ADDRESS_': address,
'EMAIL_FORMAT_': 'H' if format == 'html' else 'T',
}
data['%s_FLG' % campaign] = 'Y'
data['%s_DATE' % campaign] = date.today().strftime('%Y-%m-%d')
data['_ri_'] = settings.RESPONSYS_ID
try:
res = urllib2.urlopen('http://awesomeness.mozilla.org/pub/rf',
data=urlencode(data))
return res.code == 200
except urllib2.URLError:
return False

Просмотреть файл

@ -1,10 +1,10 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
import base64 import base64
from datetime import date
import json import json
import logging import logging
import os import os
import path import path
import shutil
import socket import socket
import sys import sys
import traceback import traceback
@ -13,6 +13,7 @@ import uuid
from django.conf import settings from django.conf import settings
from django.core.management import call_command from django.core.management import call_command
from django.utils.http import urlencode
from celeryutils import task from celeryutils import task
from statsd import statsd from statsd import statsd
@ -20,7 +21,7 @@ from tower import ugettext as _
import amo import amo
from amo.decorators import write, set_modified_on from amo.decorators import write, set_modified_on
from amo.utils import guard, slugify, resize_image, remove_icons from amo.utils import guard, resize_image, remove_icons
from addons.models import Addon from addons.models import Addon
from applications.management.commands import dump_apps from applications.management.commands import dump_apps
from applications.models import Application, AppVersion from applications.models import Application, AppVersion
@ -29,6 +30,7 @@ from files.models import FileUpload, File, FileValidation
from PIL import Image from PIL import Image
log = logging.getLogger('z.devhub.task') log = logging.getLogger('z.devhub.task')
@ -412,3 +414,32 @@ def start_perf_test_for_file(file_id, os_name, app_name, **kw):
file_ = File.objects.get(pk=file_id) file_ = File.objects.get(pk=file_id)
# TODO(Kumar) store token to retrieve results later? # TODO(Kumar) store token to retrieve results later?
perf.start_perf_test(file_, os_name, app_name) perf.start_perf_test(file_, os_name, app_name)
@task
def subscribe_to_responsys(campaign, address, format='html', source_url='',
lang='', country='', **kw):
"""
Subscribe a user to a list in responsys. There should be two
fields within the Responsys system named by the "campaign"
parameter: <campaign>_FLG and <campaign>_DATE.
"""
data = {
'LANG_LOCALE': lang,
'COUNTRY_': country,
'SOURCE_URL': source_url,
'EMAIL_ADDRESS_': address,
'EMAIL_FORMAT_': 'H' if format == 'html' else 'T',
}
data['%s_FLG' % campaign] = 'Y'
data['%s_DATE' % campaign] = date.today().strftime('%Y-%m-%d')
data['_ri_'] = settings.RESPONSYS_ID
try:
res = urllib2.urlopen('http://awesomeness.mozilla.org/pub/rf',
data=urlencode(data))
return res.code == 200
except urllib2.URLError:
return False

Просмотреть файл

@ -58,7 +58,7 @@ from versions.models import Version
from product_details import product_details from product_details import product_details
from zadmin.models import ValidationResult from zadmin.models import ValidationResult
from . import forms, tasks, feeds, responsys, signals from . import forms, tasks, feeds, signals
log = commonware.log.getLogger('z.devhub') log = commonware.log.getLogger('z.devhub')
paypal_log = commonware.log.getLogger('z.paypal') paypal_log = commonware.log.getLogger('z.paypal')
@ -1613,10 +1613,11 @@ def newsletter(request):
if request.method == 'POST': if request.method == 'POST':
if form.is_valid(): if form.is_valid():
data = form.cleaned_data data = form.cleaned_data
responsys.subscribe.delay( # Responsys expects the URL in the format example.com/foo.
'ABOUT_ADDONS', data['email'], data['format'], responsys_url = request.get_host() + request.get_full_path()
responsys.make_source_url(request), request.LANG, tasks.subscribe_to_responsys.delay('ABOUT_ADDONS', data['email'],
data['region']) data['format'], responsys_url,
request.LANG, data['region'])
messages.success(request, _('Thanks for subscribing!')) messages.success(request, _('Thanks for subscribing!'))
return redirect('devhub.community.newsletter') return redirect('devhub.community.newsletter')