16
16
#
17
17
# You should have received a copy of the GNU General Public License
18
18
# along with PyPLN. If not, see <http://www.gnu.org/licenses/>.
19
-
19
+ import pymongo
20
20
from celery import Task
21
21
22
- from pypln .backend .mongodict_adapter import MongoDictAdapter
23
-
24
22
# This import may look like an unused imported, but it is not.
25
23
# When our base task class is defined, the Celery app must have already been
26
24
# instantiated, otherwise when this code is imported elsewhere (like in a
33
31
from pypln .backend import config
34
32
35
33
34
+ mongo_client = pymongo .MongoClient (host = config .MONGODB_CONFIG ["host" ],
35
+ port = config .MONGODB_CONFIG ["port" ])
36
+ database = mongo_client [config .MONGODB_CONFIG ["database" ]]
37
+ document_collection = database [config .MONGODB_CONFIG ["collection" ]]
38
+
36
39
class PyPLNTask (Task ):
37
40
"""
38
41
A base class for PyPLN tasks. It is in charge of getting the document
@@ -48,16 +51,9 @@ def run(self, document_id):
48
51
It will call the `process` method with a dictionary containing all the
49
52
document information and will update de database with results.
50
53
"""
51
- document = MongoDictAdapter (doc_id = document_id ,
52
- host = config .MONGODB_CONFIG ['host' ],
53
- port = config .MONGODB_CONFIG ['port' ],
54
- database = config .MONGODB_CONFIG ['database' ])
55
- # Create a dictionary out of our document. We could simply pass
56
- # it on to the process method, but for now we won't let the user
57
- # manipulate the MongoDict directly.
58
- dic = {k : v for k , v in document .iteritems ()}
59
- result = self .process (dic )
60
- document .update (result )
54
+ document = document_collection .find_one ({"_id" : document_id })
55
+ result = self .process (document )
56
+ document_collection .update ({"_id" : document_id }, {"$set" : result })
61
57
return document_id
62
58
63
59
def process (self , document ):
0 commit comments