Exemplo n.º 1
0
    def wait(self, callback, **params):
        if 'since' not in params:
            params['since'] = 0

        self._params = params

        consumer = Consumer(db)

        def process(change):
            seq = change.get('seq')
            last_seq = change.get('last_seq')

            if seq is not None:
                if seq > self._params['since']:
                    self._params['since'] = seq

                callback(change)
            elif last_seq is not None:
                self._params['since'] = last_seq

        while True:
            try:
                consumer.wait(process, **self._params)
            except NoMoreData:
                pass
Exemplo n.º 2
0
    def wait(self, callback, **params):
        if 'since' not in params:
            params['since'] = 0
            
        self._params = params
    
        consumer = Consumer(db)

        def process(change):
            seq = change.get('seq')
            last_seq = change.get('last_seq')

            if seq is not None:
                if seq > self._params['since']:
                    self._params['since'] = seq
                    
                callback(change)
            elif last_seq is not None:
                self._params['since'] = last_seq
        
        while True:
            try:
                consumer.wait(process, **self._params)
            except NoMoreData:
                pass
def main():
    s = Server('http://edwdbik.fzk.de:5984')
    db = s['datadb']
    c = Consumer(db)

    #start listening since = current update sequence.
    #callback function is run.main
    #heartbeat every minute to keep the connection alive.
    c.wait(remoterun.main, since = db.info()['update_seq'], filter='proc/statusgood', feed='continuous', heartbeat=60000)  
Exemplo n.º 4
0
def main():
    s = Server('http://*****:*****@127.0.0.1:5984')
    db = s['datadb']
    c = Consumer(db)

    #start listening since = current update sequence.
    #callback function is run.main
    #heartbeat every minute to keep the connection alive.
    c.wait(callback, since = db.info()['update_seq'], filter='proc/newproc0', feed='continuous', heartbeat=60000)  
Exemplo n.º 5
0
	def resolveForever(self):
		consumer = Consumer(self.db)
		consumer.register_callback(self.resolve)
		while True:
			try:
				consumer.wait(heartbeat=True, filter="sessiondoc/scanconflicts")
				self.logger.info('Changes feed closed connection. Restarting.')
			except Exception as e:
				self.logger.info('Error connecting to CouchDB for changes:')
				self.logger.info('%s' % e)
				time.sleep(1)
Exemplo n.º 6
0
def main():
    s = Server('http://*****:*****@127.0.0.1:5984')
    db = s['datadb']
    c = Consumer(db)

    #start listening since = current update sequence.
    #callback function is run.main
    #heartbeat every minute to keep the connection alive.
    c.wait(callback,
           since=db.info()['update_seq'],
           filter='proc/newproc0',
           feed='continuous',
           heartbeat=60000)
Exemplo n.º 7
0
    def old_changes(self):
        """
        Couchdbkit < 0.6.0 changes feed listener
        http://couchdbkit.org/docs/changes_consumer.html
        """
        from couchdbkit import Consumer

        c = Consumer(self.couch_db, backend='gevent')
        while True:
            try:
                c.wait(self.parsing_processor, since=self.since, filter=self.couch_filter,
                       heartbeat=WAIT_HEARTBEAT, feed='continuous', timeout=30000, **self.extra_args)
            except Exception, ex:
                pillow_logging.exception("Exception in form listener: %s, sleeping and restarting" % ex)
                gevent.sleep(RETRY_INTERVAL)
def wait_for_changes(db_url, since):
    db = Database(db_url)
    consumer = Consumer(db)
    consumer.wait(callback, since=since, heartbeat=1000, include_docs=True)
Exemplo n.º 9
0
 def process(self, db, since):
     consumer = Consumer(db)
     params = self.get_query_params()
     consumer.wait(self.callback, since=since, heartbeat=10000, **params)
Exemplo n.º 10
0
            pdfname = pl_name
            jobname = uuid.uuid4().hex
            f = open('/tmp/%s.tex' % jobname, 'w+')
            f.write(data)
            f.close()
            try:
                for i in range(2):
                    p = subprocess.Popen([
                        'pdflatex',
                        '-output-directory', '/tmp',
                        '-interaction', 'nonstopmode',
                        '-jobname', jobname,
                        '/tmp/%s.tex' % jobname,
                    ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                    p.communicate()
                filename = '/tmp/%s.pdf' % jobname
                data = open(filename).read()
                db.put_attachment(doc, data, name=pdfname, content_type='application/pdf')
            except IOError:
                pass
    return f

if __name__ == '__main__':
    while True:
        db = Database(sys.argv[1])
        c = Consumer(db)
        last_seq = c.wait_once()['last_seq']
        c.register_callback(generate_pdf(db))
        c.wait(filter='aimpl/pl', since=last_seq, heartbeat=True)
        time.sleep(5)
Exemplo n.º 11
0
        authToken=""
        for line in lines:
            if line.startswith( "Auth=" ):
                authToken=line[5:len(line)]
        return authToken
    logging.error( "error code: "+str(result.status_code)+"; error message: "+result.content )
    return ""

# server object
server = Server('http://*****:*****@localhost:5984')

# create database
db = server.get_or_create_db("coconut")

c = Consumer(db)
def sendCouchMessage(line): 
    #print "got %s" % line 
    print json.dumps(line)
    id = line['id']
    
    print "id: " + id
    doc = db.get(id) 
    if 'phone' in doc:
    	phone = doc['phone']
    	print json.dumps(doc)
    	message = "Message from " + phone
    	print message
    	status = sendMessage( accountName, registrationId, message )
c.wait(sendCouchMessage,since=5,heartbeat=True) # Go into receive loop