2012-12-05 13:10:11 -08:00
|
|
|
import datetime
|
2024-04-24 09:50:42 -04:00
|
|
|
|
2013-05-13 18:03:17 -07:00
|
|
|
from apps.profile.models import Profile, RNewUserQueue
|
2017-02-06 19:30:59 -08:00
|
|
|
from apps.reader.models import UserSubscription, UserSubscriptionFolders
|
2024-04-24 09:50:42 -04:00
|
|
|
from apps.social.models import MActivity, MInteraction, MSocialServices
|
|
|
|
from newsblur_web.celeryapp import app
|
|
|
|
from utils import log as logging
|
2012-07-05 22:20:49 -07:00
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
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()
|
2013-05-13 18:03:17 -07:00
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
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()
|
2014-02-02 19:08:01 -08:00
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
2022-04-18 13:29:13 -04:00
|
|
|
@app.task()
|
|
|
|
def FetchArchiveFeedsForUser(user_id):
|
2022-04-18 14:29:08 -04:00
|
|
|
# subs = UserSubscription.objects.filter(user=user_id)
|
|
|
|
# user_profile = Profile.objects.get(user__pk=user_id)
|
|
|
|
# logging.user(user_profile.user, f"~FCBeginning archive feed fetches for ~SB~FG{subs.count()} feeds~SN...")
|
2022-04-18 13:29:13 -04:00
|
|
|
|
|
|
|
UserSubscription.fetch_archive_feeds_for_user(user_id)
|
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
2022-04-18 13:29:13 -04:00
|
|
|
@app.task()
|
|
|
|
def FetchArchiveFeedsChunk(user_id, feed_ids):
|
2022-04-18 14:29:08 -04:00
|
|
|
# logging.debug(" ---> Fetching archive stories: %s for %s" % (feed_ids, user_id))
|
2022-04-18 13:29:13 -04:00
|
|
|
UserSubscription.fetch_archive_feeds_chunk(user_id, feed_ids)
|
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
2022-04-18 13:29:13 -04:00
|
|
|
@app.task()
|
|
|
|
def FinishFetchArchiveFeeds(results, user_id, start_time, starting_story_count):
|
2022-04-18 14:29:08 -04:00
|
|
|
# logging.debug(" ---> Fetching archive stories finished for %s" % (user_id))
|
2022-04-18 14:08:28 -04:00
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
ending_story_count, pre_archive_count = UserSubscription.finish_fetch_archive_feeds(
|
|
|
|
user_id, start_time, starting_story_count
|
|
|
|
)
|
2022-04-18 13:29:13 -04:00
|
|
|
|
2022-04-18 16:23:52 -04:00
|
|
|
user_profile = Profile.objects.get(user__pk=user_id)
|
2022-06-22 15:53:13 -04:00
|
|
|
user_profile.send_new_premium_archive_email(ending_story_count, pre_archive_count)
|
2022-01-11 13:43:38 -05:00
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
2022-01-11 13:43:38 -05:00
|
|
|
@app.task(name="email-new-premium-pro")
|
|
|
|
def EmailNewPremiumPro(user_id):
|
|
|
|
user_profile = Profile.objects.get(user__pk=user_id)
|
|
|
|
user_profile.send_new_premium_pro_email()
|
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
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)
|
2024-04-24 09:43:56 -04:00
|
|
|
expired_profiles = Profile.objects.filter(
|
|
|
|
is_premium=True, premium_expire__lte=two_days_ago, premium_expire__gt=thirty_days_ago
|
|
|
|
)
|
2020-11-13 12:14:37 -05:00
|
|
|
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()
|
2024-04-24 09:43:56 -04:00
|
|
|
|
2020-11-13 12:14:37 -05:00
|
|
|
# Get fully expired users
|
2024-04-24 09:43:56 -04:00
|
|
|
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()
|
|
|
|
)
|
2020-11-13 12:14:37 -05:00
|
|
|
for profile in expired_profiles:
|
|
|
|
profile.setup_premium_history()
|
|
|
|
if profile.premium_expire < thirty_days_ago:
|
|
|
|
profile.send_premium_expire_email()
|
|
|
|
profile.deactivate_premium()
|
2014-02-02 19:08:01 -08:00
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
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
|
|
|
|
2024-04-24 09:43:56 -04: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)
|
2024-04-24 09:43:56 -04:00
|
|
|
|
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()
|
2019-07-16 12:00:10 -07:00
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
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)
|
2019-07-16 12:00:10 -07:00
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
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)
|