change celery Task import and task initialization as per the new version of celery

This commit is contained in:
Jonathan Math 2020-10-05 00:45:20 +07:00
parent 0e4eb419ad
commit 89e51a2937
23 changed files with 35 additions and 35 deletions

View file

@ -45,7 +45,7 @@ class MPopularityQuery(mongo.Document):
return "%s - \"%s\"" % (self.email, self.query) return "%s - \"%s\"" % (self.email, self.query)
def queue_email(self): def queue_email(self):
EmailPopularityQuery.delay(pk=self.pk) EmailPopularityQuery().delay(pk=self.pk)
@classmethod @classmethod
def ensure_all_sent(cls, queue=True): def ensure_all_sent(cls, queue=True):

View file

@ -1,4 +1,4 @@
from celery.task import Task from celery import Task
from utils import log as logging from utils import log as logging
class EmailPopularityQuery(Task): class EmailPopularityQuery(Task):

View file

@ -1,4 +1,4 @@
from celery.task import Task from celery import Task
from django.contrib.auth.models import User from django.contrib.auth.models import User
from apps.feed_import.models import UploadedOPML, OPMLImporter from apps.feed_import.models import UploadedOPML, OPMLImporter
from apps.reader.models import UserSubscription from apps.reader.models import UserSubscription

View file

@ -46,7 +46,7 @@ def opml_upload(request):
folders = opml_importer.try_processing() folders = opml_importer.try_processing()
except TimeoutError: except TimeoutError:
folders = None folders = None
ProcessOPML.delay(request.user.pk) ProcessOPML().delay(request.user.pk)
feed_count = opml_importer.count_feeds_in_opml() feed_count = opml_importer.count_feeds_in_opml()
logging.user(request, "~FR~SBOPML upload took too long, found %s feeds. Tasking..." % feed_count) logging.user(request, "~FR~SBOPML upload took too long, found %s feeds. Tasking..." % feed_count)
payload = dict(folders=folders, delayed=True, feed_count=feed_count) payload = dict(folders=folders, delayed=True, feed_count=feed_count)

View file

@ -1,4 +1,4 @@
from celery.task import Task from celery import Task
from django.contrib.auth.models import User from django.contrib.auth.models import User
from apps.notifications.models import MUserFeedNotification from apps.notifications.models import MUserFeedNotification
from utils import log as logging from utils import log as logging

View file

@ -67,7 +67,7 @@ def twitter_connect(request):
social_services.syncing_twitter = True social_services.syncing_twitter = True
social_services.save() social_services.save()
SyncTwitterFriends.delay(user_id=request.user.pk) SyncTwitterFriends().delay(user_id=request.user.pk)
logging.user(request, "~BB~FRFinishing Twitter connect") logging.user(request, "~BB~FRFinishing Twitter connect")
return {} return {}
@ -131,7 +131,7 @@ def facebook_connect(request):
social_services.syncing_facebook = True social_services.syncing_facebook = True
social_services.save() social_services.save()
SyncFacebookFriends.delay(user_id=request.user.pk) SyncFacebookFriends().delay(user_id=request.user.pk)
logging.user(request, "~BB~FRFinishing Facebook connect") logging.user(request, "~BB~FRFinishing Facebook connect")
return {} return {}

View file

@ -29,7 +29,7 @@ class LastSeenMiddleware(object):
logging.user(request, "~FG~BBRepeat visitor: ~SB%s (%s)" % ( logging.user(request, "~FG~BBRepeat visitor: ~SB%s (%s)" % (
request.user.profile.last_seen_on, ip)) request.user.profile.last_seen_on, ip))
from apps.profile.tasks import CleanupUser from apps.profile.tasks import CleanupUser
CleanupUser.delay(user_id=request.user.pk) CleanupUser().delay(user_id=request.user.pk)
elif settings.DEBUG: elif settings.DEBUG:
logging.user(request, "~FG~BBRepeat visitor (ignored): ~SB%s (%s)" % ( logging.user(request, "~FG~BBRepeat visitor (ignored): ~SB%s (%s)" % (
request.user.profile.last_seen_on, ip)) request.user.profile.last_seen_on, ip))

View file

@ -161,7 +161,7 @@ class Profile(models.Model):
def activate_premium(self, never_expire=False): def activate_premium(self, never_expire=False):
from apps.profile.tasks import EmailNewPremium from apps.profile.tasks import EmailNewPremium
EmailNewPremium.delay(user_id=self.user.pk) EmailNewPremium().delay(user_id=self.user.pk)
was_premium = self.is_premium was_premium = self.is_premium
self.is_premium = True self.is_premium = True
@ -186,7 +186,7 @@ class Profile(models.Model):
scheduled_feeds = [] scheduled_feeds = []
logging.user(self.user, "~SN~FMTasking the scheduling immediate premium setup of ~SB%s~SN feeds..." % logging.user(self.user, "~SN~FMTasking the scheduling immediate premium setup of ~SB%s~SN feeds..." %
len(scheduled_feeds)) len(scheduled_feeds))
SchedulePremiumSetup.apply_async(kwargs=dict(feed_ids=scheduled_feeds)) SchedulePremiumSetup().apply_async(kwargs=dict(feed_ids=scheduled_feeds))
UserSubscription.queue_new_feeds(self.user) UserSubscription.queue_new_feeds(self.user)

View file

@ -1,5 +1,5 @@
import datetime import datetime
from celery.task import Task from celery import Task
from apps.profile.models import Profile, RNewUserQueue from apps.profile.models import Profile, RNewUserQueue
from utils import log as logging from utils import log as logging
from apps.reader.models import UserSubscription, UserSubscriptionFolders from apps.reader.models import UserSubscription, UserSubscriptionFolders

View file

@ -166,7 +166,7 @@ class SignupForm(forms.Form):
RNewUserQueue.add_user(new_user.pk) RNewUserQueue.add_user(new_user.pk)
if new_user.email: if new_user.email:
EmailNewUser.delay(user_id=new_user.pk) EmailNewUser().delay(user_id=new_user.pk)
if getattr(settings, 'AUTO_PREMIUM_NEW_USERS', False): if getattr(settings, 'AUTO_PREMIUM_NEW_USERS', False):
new_user.profile.activate_premium() new_user.profile.activate_premium()

View file

@ -475,7 +475,7 @@ class UserSubscription(models.Model):
logging.user(user, "~BB~FW~SBQueueing NewFeeds: ~FC(%s) %s" % (len(new_feeds), new_feeds)) logging.user(user, "~BB~FW~SBQueueing NewFeeds: ~FC(%s) %s" % (len(new_feeds), new_feeds))
size = 4 size = 4
for t in (new_feeds[pos:pos + size] for pos in range(0, len(new_feeds), size)): for t in (new_feeds[pos:pos + size] for pos in range(0, len(new_feeds), size)):
NewFeeds.apply_async(args=(t,), queue="new_feeds") NewFeeds().apply_async(args=(t,), queue="new_feeds")
@classmethod @classmethod
def refresh_stale_feeds(cls, user, exclude_new=False): def refresh_stale_feeds(cls, user, exclude_new=False):

View file

@ -1,5 +1,5 @@
import datetime import datetime
from celery.task import Task from celery import Task
from utils import log as logging from utils import log as logging
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings

View file

@ -301,7 +301,7 @@ def load_feeds(request):
if len(scheduled_feeds) > 0 and request.user.is_authenticated: if len(scheduled_feeds) > 0 and request.user.is_authenticated:
logging.user(request, "~SN~FMTasking the scheduling immediate fetch of ~SB%s~SN feeds..." % logging.user(request, "~SN~FMTasking the scheduling immediate fetch of ~SB%s~SN feeds..." %
len(scheduled_feeds)) len(scheduled_feeds))
ScheduleImmediateFetches.apply_async(kwargs=dict(feed_ids=scheduled_feeds, user_id=user.pk)) ScheduleImmediateFetches().apply_async(kwargs=dict(feed_ids=scheduled_feeds, user_id=user.pk))
starred_counts, starred_count = MStarredStoryCounts.user_counts(user.pk, include_total=True) starred_counts, starred_count = MStarredStoryCounts.user_counts(user.pk, include_total=True)
if not starred_count and len(starred_counts): if not starred_count and len(starred_counts):
@ -410,7 +410,7 @@ def load_feeds_flat(request):
if len(scheduled_feeds) > 0 and request.user.is_authenticated: if len(scheduled_feeds) > 0 and request.user.is_authenticated:
logging.user(request, "~SN~FMTasking the scheduling immediate fetch of ~SB%s~SN feeds..." % logging.user(request, "~SN~FMTasking the scheduling immediate fetch of ~SB%s~SN feeds..." %
len(scheduled_feeds)) len(scheduled_feeds))
ScheduleImmediateFetches.apply_async(kwargs=dict(feed_ids=scheduled_feeds, user_id=user.pk)) ScheduleImmediateFetches().apply_async(kwargs=dict(feed_ids=scheduled_feeds, user_id=user.pk))
flat_folders = [] flat_folders = []
flat_folders_with_inactive = [] flat_folders_with_inactive = []

View file

@ -5,4 +5,4 @@ class Command(BaseCommand):
option_list = BaseCommand.option_list option_list = BaseCommand.option_list
def handle(self, *args, **options): def handle(self, *args, **options):
BackupMongo.apply() BackupMongo().apply()

View file

@ -15,6 +15,6 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
if options['broken']: if options['broken']:
TaskBrokenFeeds.apply() TaskBrokenFeeds().apply()
else: else:
TaskFeeds.apply() TaskFeeds().apply()

View file

@ -561,7 +561,7 @@ class Feed(models.Model):
# for feed_ids in (feeds[pos:pos + queue_size] for pos in xrange(0, len(feeds), queue_size)): # for feed_ids in (feeds[pos:pos + queue_size] for pos in xrange(0, len(feeds), queue_size)):
for feed_id in feeds: for feed_id in feeds:
UpdateFeeds.apply_async(args=(feed_id,), queue='update_feeds') UpdateFeeds().apply_async(args=(feed_id,), queue='update_feeds')
@classmethod @classmethod
def drain_task_feeds(cls): def drain_task_feeds(cls):
@ -2250,7 +2250,7 @@ class Feed(models.Model):
else: else:
logging.debug(' ---> [%-30s] [%s] ~FB~SBQueuing pushed stories, last pushed %s...' % (self.log_title[:30], self.pk, latest_push_date_delta)) logging.debug(' ---> [%-30s] [%s] ~FB~SBQueuing pushed stories, last pushed %s...' % (self.log_title[:30], self.pk, latest_push_date_delta))
self.set_next_scheduled_update() self.set_next_scheduled_update()
PushFeeds.apply_async(args=(self.pk, xml), queue='push_feeds') PushFeeds().apply_async(args=(self.pk, xml), queue='push_feeds')
# def calculate_collocations_story_content(self, # def calculate_collocations_story_content(self,
# collocation_measures=TrigramAssocMeasures, # collocation_measures=TrigramAssocMeasures,
@ -3047,7 +3047,7 @@ class MStarredStoryCounts(mongo.Document):
@classmethod @classmethod
def schedule_count_tags_for_user(cls, user_id): def schedule_count_tags_for_user(cls, user_id):
ScheduleCountTagsForUser.apply_async(kwargs=dict(user_id=user_id)) ScheduleCountTagsForUser().apply_async(kwargs=dict(user_id=user_id))
@classmethod @classmethod
def count_for_user(cls, user_id, total_only=False): def count_for_user(cls, user_id, total_only=False):

View file

@ -3,7 +3,7 @@ import os
import shutil import shutil
import time import time
import redis import redis
from celery.task import Task from celery import Task
from celery.exceptions import SoftTimeLimitExceeded from celery.exceptions import SoftTimeLimitExceeded
from utils import log as logging from utils import log as logging
from utils import s3_utils as s3 from utils import s3_utils as s3

View file

@ -49,7 +49,7 @@ class MUserSearch(mongo.Document):
self.save() self.save()
def schedule_index_subscriptions_for_search(self): def schedule_index_subscriptions_for_search(self):
IndexSubscriptionsForSearch.apply_async(kwargs=dict(user_id=self.user_id), IndexSubscriptionsForSearch().apply_async(kwargs=dict(user_id=self.user_id),
queue='search_indexer_tasker') queue='search_indexer_tasker')
# Should be run as a background task # Should be run as a background task
@ -122,7 +122,7 @@ class MUserSearch(mongo.Document):
if not isinstance(feed_ids, list): if not isinstance(feed_ids, list):
feed_ids = [feed_ids] feed_ids = [feed_ids]
IndexFeedsForSearch.apply_async(kwargs=dict(feed_ids=feed_ids, user_id=user_id), IndexFeedsForSearch().apply_async(kwargs=dict(feed_ids=feed_ids, user_id=user_id),
queue='search_indexer') queue='search_indexer')
@classmethod @classmethod

View file

@ -1,4 +1,4 @@
from celery.task import Task from celery import Task
class IndexSubscriptionsForSearch(Task): class IndexSubscriptionsForSearch(Task):

View file

@ -474,7 +474,7 @@ class MSocialProfile(mongo.Document):
if followee.protected and user_id != self.user_id and not force: if followee.protected and user_id != self.user_id and not force:
from apps.social.tasks import EmailFollowRequest from apps.social.tasks import EmailFollowRequest
EmailFollowRequest.apply_async(kwargs=dict(follower_user_id=self.user_id, EmailFollowRequest().apply_async(kwargs=dict(follower_user_id=self.user_id,
followee_user_id=user_id), followee_user_id=user_id),
countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS) countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS)
return return
@ -500,7 +500,7 @@ class MSocialProfile(mongo.Document):
if not force: if not force:
from apps.social.tasks import EmailNewFollower from apps.social.tasks import EmailNewFollower
EmailNewFollower.apply_async(kwargs=dict(follower_user_id=self.user_id, EmailNewFollower().apply_async(kwargs=dict(follower_user_id=self.user_id,
followee_user_id=user_id), followee_user_id=user_id),
countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS) countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS)

View file

@ -1,5 +1,5 @@
from bson.objectid import ObjectId from bson.objectid import ObjectId
from celery.task import Task from celery import Task
from apps.social.models import MSharedStory, MSocialProfile, MSocialServices, MSocialSubscription from apps.social.models import MSharedStory, MSocialProfile, MSocialServices, MSocialSubscription
from django.contrib.auth.models import User from django.contrib.auth.models import User
from utils import log as logging from utils import log as logging

View file

@ -621,7 +621,7 @@ def mark_story_as_shared(request):
}) })
if source_user_id: if source_user_id:
shared_story.set_source_user_id(int(source_user_id)) shared_story.set_source_user_id(int(source_user_id))
UpdateRecalcForSubscription.delay(subscription_user_id=request.user.pk, UpdateRecalcForSubscription().delay(subscription_user_id=request.user.pk,
shared_story_id=str(shared_story.id)) shared_story_id=str(shared_story.id))
logging.user(request, "~FCSharing ~FM%s: ~SB~FB%s" % (story.story_title[:20], comments[:30])) logging.user(request, "~FCSharing ~FM%s: ~SB~FB%s" % (story.story_title[:20], comments[:30]))
else: else:
@ -659,13 +659,13 @@ def mark_story_as_shared(request):
if post_to_services: if post_to_services:
for service in post_to_services: for service in post_to_services:
if service not in shared_story.posted_to_services: if service not in shared_story.posted_to_services:
PostToService.delay(shared_story_id=str(shared_story.id), service=service) PostToService().delay(shared_story_id=str(shared_story.id), service=service)
if shared_story.source_user_id and shared_story.comments: if shared_story.source_user_id and shared_story.comments:
EmailStoryReshares.apply_async(kwargs=dict(shared_story_id=str(shared_story.id)), EmailStoryReshares().apply_async(kwargs=dict(shared_story_id=str(shared_story.id)),
countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS) countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS)
EmailFirstShare.apply_async(kwargs=dict(user_id=request.user.pk)) EmailFirstShare().apply_async(kwargs=dict(user_id=request.user.pk))
if format == 'html': if format == 'html':
stories = MSharedStory.attach_users_to_stories(stories, profiles) stories = MSharedStory.attach_users_to_stories(stories, profiles)
@ -812,7 +812,7 @@ def save_comment_reply(request):
story_feed_id=feed_id, story_feed_id=feed_id,
story_title=shared_story.story_title) story_title=shared_story.story_title)
EmailCommentReplies.apply_async(kwargs=dict(shared_story_id=str(shared_story.id), EmailCommentReplies().apply_async(kwargs=dict(shared_story_id=str(shared_story.id),
reply_id=str(reply.reply_id)), reply_id=str(reply.reply_id)),
countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS) countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS)

View file

@ -1,4 +1,4 @@
from celery.task import Task from celery import Task
from apps.statistics.models import MStatistics from apps.statistics.models import MStatistics
from apps.statistics.models import MFeedback from apps.statistics.models import MFeedback
# from utils import log as logging # from utils import log as logging