예제 #1
0
        )

        for user_vip in user_vip_query:
            user_vip.expire_time += relativedelta(
                months=3
            )
            user_vip.save()
            PackageUtils.update_uservip_package(user_vip)

        return user_vip_query.count()


# 自助服务每周添加聘点
point_task = VipPointTask()
asyn_vip_point_task = app.task(
    name='vip-point-task'
)(point_task.vip_point_task)

# 省心服务过期任务
expire_manual_service = app.task(
    name='expire-manual-service'
)(ExpireManualService.expire_manual_service)

# 自助服务过期任务
expire_self_service = app.task(
    name='expire-self-service'
)(ExpireSelfService.expire_self_service)

# 体验用户自动续期
renew_experience_user = app.task(
    name='renew-experience-user'
예제 #2
0
        headers = {'Authorization': cls.get_crypto_token(token_key)}
        return headers

    @classmethod
    @retry(UnAuthException, tries=3, delay=1)
    def auth_request(cls,
                     url,
                     data=None,
                     method='get',
                     cache_key='spider_msg_token'):

        auth_header = cls.get_auth_header(cache_key)
        params = {'data': data, 'headers': auth_header}

        response = cls.request_api(url, params, method=method)

        if response.status_code == 401:
            cache.delete(cache_key)
            raise UnAuthException
        return response

    @classmethod
    def send_download_msg(cls, resume_id):

        url = SPIDER_DOWNLOAD_MSG_REQ_URL + str(resume_id) + '/'
        return cls.auth_request(url)


asyn_send_download_msg = app.task(name='send_download_msg')(
    SpiderMsgDispatch.send_download_msg)
예제 #3
0
            action=0
        )

        delete_list = []
        for resume_task in reco_resume_task:
            feed_user = resume_task.feed.user
            resume = resume_task.upload_resume

            has_task = UserTaskResume.objects.filter(
                task__feed__user=feed_user,
                resume=resume,
            ).exists()

            if has_task:
                delete_list.append(resume_task.id)

        RecoResumeTask.objects.filter(
            id__in=delete_list,
        ).delete()


reco_resume_task = SyncRecoResumeTask()
asyn_reco_resume_task = app.task(
    name='pinbot-reco-resume-task'
)(reco_resume_task.sync_task)

clean_task = CleanRecoTask()
clean_reco_resume_task = app.task(
    name='pinbot-clean-reco-task'
)(clean_task.clean_reco_task)
예제 #4
0
# coding: utf-8

from django.core.mail import EmailMessage

from Pinbot.settings import DEFAULT_FROM_EMAIL

from pin_celery.celery_app import app


class DjangoMail(object):
    @classmethod
    def send_mail(cls, to, subject, html):
        msg = EmailMessage(subject, html, DEFAULT_FROM_EMAIL, [to])
        msg.content_subtype = "html"
        result = msg.send()
        return result


asyn_django_mail = app.task(name="django-send-mail")(DjangoMail.send_mail)
예제 #5
0
# coding: utf-8

from django.core.mail import EmailMessage

from Pinbot.settings import DEFAULT_FROM_EMAIL

from pin_celery.celery_app import app


class DjangoMail(object):
    @classmethod
    def send_mail(cls, to, subject, html):
        msg = EmailMessage(
            subject,
            html,
            DEFAULT_FROM_EMAIL,
            [to],
        )
        msg.content_subtype = "html"
        result = msg.send()
        return result


asyn_django_mail = app.task(name='django-send-mail')(DjangoMail.send_mail)
예제 #6
0
        reco_resume_task = RecoResumeTask.objects.select_related(
            'feed',
            'feed__user',
            'upload_resume',
        ).filter(action=0)

        delete_list = []
        for resume_task in reco_resume_task:
            feed_user = resume_task.feed.user
            resume = resume_task.upload_resume

            has_task = UserTaskResume.objects.filter(
                task__feed__user=feed_user,
                resume=resume,
            ).exists()

            if has_task:
                delete_list.append(resume_task.id)

        RecoResumeTask.objects.filter(id__in=delete_list, ).delete()


reco_resume_task = SyncRecoResumeTask()
asyn_reco_resume_task = app.task(name='pinbot-reco-resume-task')(
    reco_resume_task.sync_task)

clean_task = CleanRecoTask()
clean_reco_resume_task = app.task(name='pinbot-clean-reco-task')(
    clean_task.clean_reco_task)
예제 #7
0
# coding: utf-8

import requests
from django.conf import settings

from pin_celery.celery_app import app


class SMSUtils(object):

    SMS_SEND_URL = settings.SMS_SEND_URL
    SMS_SEND_APIKEY = settings.SMS_SEND_APIKEY

    @classmethod
    def send(cls, phone, content):
        param = {
            'apikey': cls.SMS_SEND_APIKEY,
            'mobile': phone,
            'text': content,
        }

        res = requests.post(
            url=cls.SMS_SEND_URL,
            data=param,
        )
        ret = res.json()
        return ret


asyn_send_sms = app.task(name='send-sms-task')(SMSUtils.send)
예제 #8
0
    @classmethod
    def bat_mail(
            cls,
            email_to,
            subject,
            html,
            files={},
            email_from=EMAIL_FROM,
            fromname=FROM_NAME,
            app_id=BAT_APP_ID,
            app_key=BAT_APP_KEY,
            label=None,
    ):
        return cls.send_mail(
            email_to,
            subject,
            html,
            files={},
            email_from=email_from,
            fromname=fromname,
            app_id=app_id,
            app_key=app_key,
            label=None,
        )


asyn_bat_mail = app.task(name='send-bat-mail')(SubMailUtils.bat_mail)
asyn_send_mail = app.task(name='send-trigger-mail')(SubMailUtils.send_mail)
sendcloud_bat_mail = app.task(name='sendcloud-bat-mail')(MailUtils.bat_mail)
예제 #9
0
        headers = {
            'Authorization': cls.get_crypto_token(token_key)
        }
        return headers

    @classmethod
    @retry(UnAuthException, tries=3, delay=1)
    def auth_request(cls, url, data=None, method='get', cache_key='spider_msg_token'):

        auth_header = cls.get_auth_header(cache_key)
        params = {
            'data': data,
            'headers': auth_header
        }

        response = cls.request_api(url, params, method=method)

        if response.status_code == 401:
            cache.delete(cache_key)
            raise UnAuthException
        return response

    @classmethod
    def send_download_msg(cls, resume_id):

        url = SPIDER_DOWNLOAD_MSG_REQ_URL + str(resume_id) + '/'
        return cls.auth_request(url)


asyn_send_download_msg = app.task(name='send_download_msg')(SpiderMsgDispatch.send_download_msg)
예제 #10
0
from .models import EasterEgg

from pin_celery.celery_app import app

from pin_utils.django_utils import (
    today_rest_seconds,
)


class LoadEggData(object):
    gift_pool_key = 'EGG_GIFT_POOL'
    grant_gift_key = 'EGG_GRANT_GIFT'

    def load_data(self):
        egg_data_pool = dict(list(
            EasterEgg.objects.filter(is_active=True).values_list('code_name', 'amount'))
        )

        if not egg_data_pool:
            return False

        expire_time = today_rest_seconds()
        cache.set(self.gift_pool_key, egg_data_pool, expire_time)
        return True


load_egg_task = LoadEggData()
asyn_load_egg_task = app.task(
    name='pinbot-load-egg-task'
)(load_egg_task.load_data)
예제 #11
0
# coding: utf-8

from pin_celery.celery_app import app

from .email_utils import UselessEmailUtils

sync_useless_email_task = app.task(name='sync-useless-email-task')(
    UselessEmailUtils.sync_useless_email)
예제 #12
0
        user_vip_query = UserVip.objects.select_related('user', ).filter(
            is_active=True,
            vip_role__code_name='experience_user',
            expire_time__lt=expire_time,
        )

        for user_vip in user_vip_query:
            user_vip.expire_time += relativedelta(months=3)
            user_vip.save()
            PackageUtils.update_uservip_package(user_vip)

        return user_vip_query.count()


# 自助服务每周添加聘点
point_task = VipPointTask()
asyn_vip_point_task = app.task(name='vip-point-task')(
    point_task.vip_point_task)

# 省心服务过期任务
expire_manual_service = app.task(name='expire-manual-service')(
    ExpireManualService.expire_manual_service)

# 自助服务过期任务
expire_self_service = app.task(name='expire-self-service')(
    ExpireSelfService.expire_self_service)

# 体验用户自动续期
renew_experience_user = app.task(name='renew-experience-user')(
    RenewExperienceUser.renew)
예제 #13
0
    @classmethod
    def delete_cache_code(self, mobile, action_name):
        code_key = '{0}_{1}'.format(mobile, action_name)
        cache.delete(code_key)
        return True

    @classmethod
    def get_send_data(self, mobile, code, action_name):
        send_tpl_content = SMS_TEMPLATES.get(action_name)
        if not send_tpl_content:
            return False
        text = send_tpl_content % (code, SMS_CODE_EXPIRE_TIME / 60)

        send_data = {'apikey': SMS_SEND_APIKEY, 'mobile': mobile, 'text': text}

        return send_data

    @classmethod
    @retry(TIMEOUT_EXCEPTION, delay=7)
    def send_sms(self, mobile, action_name):

        code = self.generation_code(mobile, action_name)
        send_data = self.get_send_data(mobile, code, action_name)
        if not send_data:
            return False
        rep = requests.post(url=SMS_SEND_URL, data=send_data)
        return rep.json()


asyn_send_sms_code = app.task(name='send-sms-code')(SmsCode.send_sms)
예제 #14
0
# coding: utf-8

import requests
from django.conf import settings

from pin_celery.celery_app import app


class SMSUtils(object):

    SMS_SEND_URL = settings.SMS_SEND_URL
    SMS_SEND_APIKEY = settings.SMS_SEND_APIKEY

    @classmethod
    def send(cls, phone, content):
        param = {
            'apikey': cls.SMS_SEND_APIKEY,
            'mobile': phone,
            'text': content,
        }

        res = requests.post(
            url=cls.SMS_SEND_URL,
            data=param,
        )
        ret = res.json()
        return ret

asyn_send_sms = app.task(name='send-sms-task')(SMSUtils.send)
예제 #15
0
import requests

from pin_utils.retry import retry

from pin_celery.celery_app import app

TIMEOUT_EXCEPTION = requests.exceptions.ConnectionError


class MailGunUtils(object):

    API = 'https://api.mailgun.net/v2/email.pinbot.me/messages'
    API_KEY = 'key-02bdc2dd409792588e442476b7d1b441'
    FROM = '聘宝<*****@*****.**>'

    @classmethod
    @retry(TIMEOUT_EXCEPTION, delay=7)
    def send_mail(cls, to, subject, html):
        result = requests.post(cls.API,
                               auth=("api", cls.API_KEY),
                               data={
                                   "from": cls.FROM,
                                   "to": to,
                                   "subject": subject,
                                   "html": html,
                               })
        return True if result.status_code == 200 else False


asyn_gun_mail = app.task(name='gun-send-mail')(MailGunUtils.send_mail)
예제 #16
0
    def get_send_data(self, mobile, code, action_name):
        send_tpl_content = SMS_TEMPLATES.get(action_name)
        if not send_tpl_content:
            return False
        text = send_tpl_content % (code, SMS_CODE_EXPIRE_TIME / 60)

        send_data = {
            'apikey': SMS_SEND_APIKEY,
            'mobile': mobile,
            'text': text
        }

        return send_data

    @classmethod
    @retry(TIMEOUT_EXCEPTION, delay=7)
    def send_sms(self, mobile, action_name):

        code = self.generation_code(mobile, action_name)
        send_data = self.get_send_data(mobile, code, action_name)
        if not send_data:
            return False
        rep = requests.post(
            url=SMS_SEND_URL,
            data=send_data
        )
        return rep.json()


asyn_send_sms_code = app.task(name='send-sms-code')(SmsCode.send_sms)
예제 #17
0
from pin_utils.retry import retry

from pin_celery.celery_app import app

TIMEOUT_EXCEPTION = requests.exceptions.ConnectionError


class MailGunUtils(object):

    API = 'https://api.mailgun.net/v2/email.pinbot.me/messages'
    API_KEY = 'key-02bdc2dd409792588e442476b7d1b441'
    FROM = '聘宝<*****@*****.**>'

    @classmethod
    @retry(TIMEOUT_EXCEPTION, delay=7)
    def send_mail(cls, to, subject, html):
        result = requests.post(
            cls.API,
            auth=("api", cls.API_KEY),
            data={
                "from": cls.FROM,
                "to": to,
                "subject": subject,
                "html": html,
            }
        )
        return True if result.status_code == 200 else False


asyn_gun_mail = app.task(name='gun-send-mail')(MailGunUtils.send_mail)
예제 #18
0
# coding: utf-8

from pin_celery.celery_app import app

from .email_utils import UselessEmailUtils

sync_useless_email_task = app.task(
    name='sync-useless-email-task'
)(UselessEmailUtils.sync_useless_email)