I am using django-celery worker to download web page. And I have below code to ensure saving.
def ensure_save(obj):
try:
obj.save()
except Exception as e:
time.sleep(10)
logger.error(u'############# save %s fail, error:%s.Do rerty#############' % (obj.url, e))
ensure_save(obj)
task:
@shared_task()
def fetch_article(job_id, url, title=None, cat=None, date=None):
# logger.info(u'fetch_article:%s' % url)
a = Article(job_id=job_id, url=url)
try:
a.page = fetch(url)
except Exception as e:
a.status = 2
a.error_msg = e
# maybe some db error cause save fail
ensure_save(a)
I get such error msg while task running:
############# save http://ift.tt/1M71i4E fail, error:cannot start a transaction within a transaction.Do rerty#############
I can not understand what the error say, ensure_save is just retry django model's save method.
Aucun commentaire:
Enregistrer un commentaire