Skip to content

Commit

Permalink
perf: async sms task params can json
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Jiangweidong authored and BaiJiangJie committed Jul 12, 2024
1 parent 247f4d5 commit c0d2efa
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions apps/common/utils/verify_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
logger = get_logger(__file__)


@shared_task(verbose_name=_('Send email'))
def send_async(sender):
sender.gen_and_send()
@shared_task(verbose_name=_('Send SMS code'))
def send_sms_async(target, code):
SMS().send_verify_code(target, code)


class SendAndVerifyCodeUtil(object):
Expand All @@ -35,7 +35,7 @@ def gen_and_send_async(self):
logger.warning('Send sms too frequently, delay {}'.format(ttl))
raise CodeSendTooFrequently(ttl)

return send_async.apply_async(kwargs={"sender": self}, priority=100)
return self.gen_and_send()

def gen_and_send(self):
try:
Expand Down Expand Up @@ -72,13 +72,15 @@ def __generate(self):
return code

def __send_with_sms(self):
sms = SMS()
sms.send_verify_code(self.target, self.code)
send_sms_async.apply_async(args=(self.target, self.code), priority=100)

def __send_with_email(self):
subject = self.other_args.get('subject')
message = self.other_args.get('message')
send_mail_async(subject, message, [self.target], html_message=message)
subject = self.other_args.get('subject', '')
message = self.other_args.get('message', '')
send_mail_async.apply_async(
args=(subject, message, [self.target]),
kwargs={'html_message': message}, priority=100
)

def __send(self, code):
"""
Expand Down

0 comments on commit c0d2efa

Please sign in to comment.