celery task 數據庫查詢 財富值48?
在使用celery時,函數中修改數據庫,commit后調用celery的task查詢剛才添加的數據進行其他操作,總會出現找不到的情況,求解。
調用task部分代碼
... try: db.session.commit() except Exception as e: current_app.logger.error(str(e)) db.session.rollback() if not ci_existed:# only add self.delete(ci.ci_id) return abort(500, "add CI error") his_manager = CIAttributeHistoryManger() his_manager.add(ci.ci_id, histories) ci_cache.apply_async([ci.ci_id], queue="async") # add bj ci add_ci_bj.apply_async([ci_type.type_name, None, ci.ci_id], queue="async") return ci.ci_id
c<愛尬聊_百科網>elery的task函數
@celery.task(name="xxxxxxx", queue="async") def add_ci_bj(ci_type, first_id, second_id): param, status = lib.ci.CIManager().get_relations(first_id, second_id, is_async=True) ...
task中調用的函數
def get_relations(self, first_id, second_id, is_async=False): start = time.clock() try: second = self.get_ci_by_id(second_id, need_children=False) except Exception as e: return None, "get ci by id error: first %s, second %s, e %s, is_async:%s" % (first_id, second_id, e, is_async) ...
get_relation中的exception老是被觸發,也就是查不到second_id對應的數據,有遇到過的么???求解
