Contenu connexe
Similaire à MongoUK 2011 - Rplacing RabbitMQ with MongoDB
Similaire à MongoUK 2011 - Rplacing RabbitMQ with MongoDB (20)
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
- 23. Implementation
• Consumers
db.runCommand(
{ findAndModify : <collection>, <options> } )
query: filter (WHERE)
{ query: { hats: 5 } }
- 24. Implementation
• Consumers
db.runCommand(
{ findAndModify : <collection>, <options> } )
sort: selects the first one on multi-match
{ sort: { added: -1 } }
- 25. Implementation
• Consumers
db.runCommand(
{ findAndModify : <collection>, <options> } )
update: modifier object
{ update: { $set: {inProg: true, start: new
Date()} } }
- 26. Implementation
• Consumers
db.runCommand(
{ findAndModify : <collection>, <options> } )
remove: true = deletes on return
new: true = returns modified object
fields: return specific fields
upsert: true = create object if !exists()
- 28. Implementation
• Consumers
def run(self):
import time, sched
sc = sched.scheduler(time.time, time.sleep)
self.poll(sc)
sc.run()
def poll(self, sc):
doStuff()
sc.enter(10, 1, self.poll, (sc,))
- 30. Implementation
• Consumers
from daemon import Daemon
class pantalaimon(Daemon):
def run(self): # Do stuff
pineMarten = pantalaimon('/path/to/pid.pid')
pineMarten.start()
https://github.com/boxedice/python-daemon
- 31. Implementation
• Consumers
from daemon import Daemon
class pantalaimon(Daemon):
def run(self):
import time, sched
sc = sched.scheduler(time.time, time.sleep)
self.poll(sc)
sc.run()
def poll(self, sc):
doStuff()
sc.enter(10, 1, self.poll, (sc,))
https://github.com/boxedice/python-daemon
- 33. Implementation
• GC
now = datetime.datetime.now()
difference = datetime.timedelta(seconds=10)
timeout = now - difference
queue.find({'inProg' : True, 'start' :
{'$lte' : timeout} })