NewsBlur/apps/profile/tasks.py

77 lines
3.1 KiB
Python
Raw Normal View History

2012-12-05 13:10:11 -08:00
import datetime
from newsblur_web.celeryapp import app
from apps.profile.models import Profile, RNewUserQueue
2012-12-05 13:10:11 -08:00
from utils import log as logging
from apps.reader.models import UserSubscription, UserSubscriptionFolders
from apps.social.models import MSocialServices, MActivity, MInteraction
2020-11-13 13:26:25 -05:00
@app.task(name="email-new-user")
2020-11-13 12:14:37 -05:00
def EmailNewUser(user_id):
user_profile = Profile.objects.get(user__pk=user_id)
user_profile.send_new_user_email()
2020-11-13 13:26:25 -05:00
@app.task(name="email-new-premium")
2020-11-13 12:14:37 -05:00
def EmailNewPremium(user_id):
user_profile = Profile.objects.get(user__pk=user_id)
user_profile.send_new_premium_email()
2020-11-13 13:26:25 -05:00
@app.task(name="premium-expire")
2020-11-13 12:14:37 -05:00
def PremiumExpire(**kwargs):
# Get expired but grace period users
two_days_ago = datetime.datetime.now() - datetime.timedelta(days=2)
thirty_days_ago = datetime.datetime.now() - datetime.timedelta(days=30)
expired_profiles = Profile.objects.filter(is_premium=True,
premium_expire__lte=two_days_ago,
premium_expire__gt=thirty_days_ago)
logging.debug(" ---> %s users have expired premiums, emailing grace..." % expired_profiles.count())
for profile in expired_profiles:
if profile.grace_period_email_sent():
continue
profile.setup_premium_history()
if profile.premium_expire < two_days_ago:
profile.send_premium_expire_grace_period_email()
2020-11-13 12:14:37 -05:00
# Get fully expired users
expired_profiles = Profile.objects.filter(is_premium=True,
premium_expire__lte=thirty_days_ago)
logging.debug(" ---> %s users have expired premiums, deactivating and emailing..." % expired_profiles.count())
for profile in expired_profiles:
profile.setup_premium_history()
if profile.premium_expire < thirty_days_ago:
profile.send_premium_expire_email()
profile.deactivate_premium()
2020-11-13 13:26:25 -05:00
@app.task(name="activate-next-new-user")
2020-11-13 12:14:37 -05:00
def ActivateNextNewUser():
RNewUserQueue.activate_next()
2017-12-20 15:58:34 -08:00
2020-11-13 13:26:25 -05:00
@app.task(name="cleanup-user")
2020-11-13 12:14:37 -05:00
def CleanupUser(user_id):
UserSubscription.trim_user_read_stories(user_id)
UserSubscription.verify_feeds_scheduled(user_id)
Profile.count_all_feed_subscribers_for_user(user_id)
MInteraction.trim(user_id)
MActivity.trim(user_id)
UserSubscriptionFolders.add_missing_feeds_for_user(user_id)
UserSubscriptionFolders.compact_for_user(user_id)
2021-12-07 10:45:00 -05:00
UserSubscription.refresh_stale_feeds(user_id)
2020-11-13 12:14:37 -05:00
try:
ss = MSocialServices.objects.get(user_id=user_id)
except MSocialServices.DoesNotExist:
logging.debug(" ---> ~FRCleaning up user, can't find social_services for user_id: ~SB%s" % user_id)
return
ss.sync_twitter_photo()
2020-11-13 13:26:25 -05:00
@app.task(name="clean-spam")
2020-11-13 12:14:37 -05:00
def CleanSpam():
logging.debug(" ---> Finding spammers...")
Profile.clear_dead_spammers(confirm=True)
2020-11-13 13:26:25 -05:00
@app.task(name="reimport-stripe-history")
2020-11-13 12:14:37 -05:00
def ReimportStripeHistory():
logging.debug(" ---> Reimporting Stripe history...")
Profile.reimport_stripe_history(limit=10, days=1)
2017-12-20 15:58:34 -08:00