<s> from functools import wraps <EOL> import logging <EOL> from celery import task <EOL> from django . db import IntegrityError <EOL> from django_facebook . utils import get_class_for <EOL> from django_facebook . signals import facebook_token_extend_finished <EOL> logger = logging . getLogger ( __name__ ) <EOL> @ task . task ( ignore_result = True ) <EOL> def extend_access_token ( profile , access_token ) : <EOL> '''<STR_LIT>''' <EOL> results = profile . _extend_access_token ( access_token ) <EOL> return results <EOL> @ task . task ( ignore_result = True ) <EOL> def store_likes ( user , likes ) : <EOL> '''<STR_LIT>''' <EOL> converter_class = get_class_for ( '<STR_LIT>' ) <EOL> logger . info ( '<STR_LIT>' % len ( likes ) ) <EOL> converter_class . _store_likes ( user , likes ) <EOL> return likes <EOL> @ task . task ( ignore_result = True ) <EOL> def store_friends ( user , friends ) : <EOL> '''<STR_LIT>''' <EOL> converter_class = get_class_for ( '<STR_LIT>' ) <EOL> logger . info ( '<STR_LIT>' % len ( friends ) ) <EOL> converter_class . _store_friends ( user , friends ) <EOL> return friends <EOL> @ task . task ( ignore_result = True ) <EOL> def get_and_store_likes ( user , facebook ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> logger . info ( '<STR_LIT>' , user . id ) <EOL> stored_likes = facebook . _get_and_store_likes ( user ) <EOL> logger . info ( '<STR_LIT>' , len ( stored_likes ) ) <EOL> return stored_likes <EOL> except IntegrityError as e : <EOL> logger . warn ( <EOL> '<STR_LIT>' , user . id , e ) <EOL> @ task . task ( ignore_result = True ) <EOL> def get_and_store_friends ( user , facebook ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> logger . info ( '<STR_LIT>' , user . id ) <EOL> stored_friends = facebook . _get_and_store_friends ( user ) <EOL> logger . info ( '<STR_LIT>' , len ( stored_friends ) ) <EOL> return stored_friends <EOL> except IntegrityError as e : <EOL> logger . warn ( <EOL> '<STR_LIT>' , user . id , e ) <EOL> @ task . task ( ignore_result = True ) <EOL> def remove_share ( share ) : <EOL> '''<STR_LIT>''' <EOL> share . _remove ( ) <EOL> @ task . task ( ignore_result = True ) <EOL> def retry_open_graph_share ( share , reset_retries = False ) : <EOL> '''<STR_LIT>''' <EOL> logger . info ( '<STR_LIT>' , share ) <EOL> share . retry ( reset_retries = reset_retries ) <EOL> @ task . task ( ignore_result = True ) <EOL> def retry_open_graph_shares_for_user ( user ) : <EOL> '''<STR_LIT>''' <EOL> from django_facebook . models import OpenGraphShare <EOL> shares = OpenGraphShare . objects . recently_failed ( ) . filter ( user = user ) [ : <NUM_LIT:1000> ] <EOL> shares = list ( shares ) <EOL> logger . info ( '<STR_LIT>' , len ( shares ) , user ) <EOL> for share in shares : <EOL> retry_open_graph_share ( share , reset_retries = True ) <EOL> def token_extended_connect ( sender , user , profile , token_changed , old_token , ** kwargs ) : <EOL> from django_facebook import settings as facebook_settings <EOL> if facebook_settings . FACEBOOK_CELERY_TOKEN_EXTEND : <EOL> retry_open_graph_shares_for_user . apply_async ( args = [ user ] , countdown = <NUM_LIT> ) <EOL> facebook_token_extend_finished . connect ( token_extended_connect ) </s>
