2017-09-01 76 views
1

我是新来的python,但我知道自我是自动传递。我无法理解为什么我得到这个错误,我得到同样的错误getGraph函数以及2需要1给定。 这里怎么回事?TypeError:func()只需要1个参数(0给出)

CreateDoc是CeleryTasks.py和insert_manager在MongoTriggers.py

@app.task 
    def createDoc(self): 
     print ("CeleryTasks:CreateDoc") 
     if 'refs' not in self.data: 
      return 

     print(self.data['refs']) 

     for id in self.data['refs']: 
      doc = self.db[self.collName].find_one({'_id': id}) 
      if doc is None: 
       insertedID = self.db[self.collName].insert_one({ 
        "_id": id 
       }) 

       print (insertedID) 

    #Trigger on Mongo Operations 
    def insert_manager(op_document): 
     print("Data Inserted") 
     # pprint.pprint (op_document) 
     data = op_document['o'] 
     ns = op_document['ns'].split('.') 
     # pprint.pprint (data) 
     docID = op_document['o']['_id'] 
     tasks = CeleryTasks(port, docID, dbName, collectionName, data) 
     tasks.createDoc() 
     tasks.getGraph.delay(docID) 
+0

嗨,哪一行会导致此错误? – user10089632

+0

tasks.createDoc.delay() 它相当于tasks.createDoc(),这也给出了错误。 – Sam

+0

你需要提供多长时间来延迟例子'tasks.createDoc.delay()'将延迟6秒 – user10089632

回答

0

self时,它的类的方法总是通过。

芹菜任务是独立的功能。你可以添加self参数,通过app修饰器添加bind=True,但它用于不同的目的:bounded tasks

+0

是的!有效。基本上,我可以在不传递自己的参数的情况下完成该功能所需的其他参数。但是,如果我通过自己并使芹菜任务成为一项约束任务。当我使用self时,它给了我一个函数内部的错误。 你知道为什么会发生这种情况吗?例如 '@ app.task(绑定=真) DEF createDoc(个体,分贝,collName,数据): 分贝= self.db ' 它给错误** AttributeError的: 'createDoc' 对象没有属性“分贝'** – Sam

+0

所以你可以接受答案/ upvote吗? :-) – ItayB

+1

我已经做了upvote它。但它说我的声望低于15,所以他们不会显示它。无论如何,谢谢。 – Sam

相关问题