Add new Agent class to Python API, for writing Store agents
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import logging
|
||||
import time
|
||||
|
||||
from bongo.BongoError import BongoError
|
||||
from libbongo.libs import bongojson, msgapi
|
||||
from bongo.store.StoreClient import DocTypes, StoreClient
|
||||
|
||||
class Agent:
|
||||
log = logging.getLogger("Bongo.Error")
|
||||
running = True
|
||||
store = None
|
||||
|
||||
def __init__(self, name='Undefined'):
|
||||
self.name = name
|
||||
self.log.debug("Starting agent '%s'" % (name))
|
||||
|
||||
def connect(self, user, store):
|
||||
self.store = StoreClient(user, store, authPassword="bongo", eventCallback=self.callback)
|
||||
|
||||
def callback(self, response):
|
||||
# we want to override this in the subclass
|
||||
self.log.error("Callback received and not handled")
|
||||
pass
|
||||
|
||||
# without a proper event system in the store, we
|
||||
# essentially have to poll. FIXME.
|
||||
def waitForEvents(self):
|
||||
while self.running:
|
||||
self.store.NoOp()
|
||||
time.sleep(5)
|
||||
|
||||
self.store.Quit()
|
||||
@@ -130,7 +130,7 @@ class CommandStream:
|
||||
# gets eaten.
|
||||
rCode = 0
|
||||
if self.eventCallback:
|
||||
self.eventCallback(Response(rCode, s[5:])
|
||||
self.eventCallback(Response(rCode, s[5:]))
|
||||
|
||||
return Response(rCode, s[5:])
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ class StoreClient:
|
||||
|
||||
self.stream = self.connection.stream
|
||||
if eventCallback:
|
||||
self.stream.setEventCallback(callback)
|
||||
self.stream.setEventCallback(eventCallback)
|
||||
|
||||
# if we authed with a cookie or password, we don't need to USER
|
||||
if not authCookie and not authPassword and user is not None:
|
||||
@@ -947,5 +947,4 @@ class StoreClient:
|
||||
def Reset(self) :
|
||||
self.stream.Write("RESET\r\n")
|
||||
self.stream.GetResponse()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user