@task.task(ignore_result=True)
def get_and_store_friends(user, facebook):
 try:
  logger.info('attempting to get and store friends for %s', user.id)
  stored_friends = facebook._get_and_store_friends(user)
  logger.info('celery is storing %s friends', len(stored_friends))
  return stored_friends
 except IntegrityError as e:
  logger.warn('get_and_store_friends failed for %s with error %s', user.id, e)

@ task . task ( ignore_result = True ) def get_and_store_friends ( user , facebook ) : try : logger . info ( 'attempting to get and store friends for %s' , user . id ) stored_friends = facebook . _get_and_store_friends ( user ) logger . info ( 'celery is storing %s friends' , len ( stored_friends ) ) return stored_friends except IntegrityError as e : logger . warn ( 'get_and_store_friends failed for %s with error %s' , user . id , e )
since facebook is quite slow this version also runs the get on the background inserting again will not cause any errors .