def index(): campaign = {} try: response = berlioz.service('api').request().get('/amount') body = json.loads(response.text) campaign['amount'] = '$' + str(body['value']) except Exception as ex: campaign['amount'] = 'N/A' campaign['error'] = str(ex) recent = {} try: response = berlioz.service('api').request().get('/entries') body = json.loads(response.text) recent['entries'] = body['entries'] except Exception as ex: recent['entries'] = [] recent['error'] = str(ex) return render_template('index.html', campaign=campaign, recent=recent)
def hello_world(): settings = [ {'name': 'Identity', 'value': berlioz.identity() }, {'name': 'Task ID', 'value': os.environ.get('BERLIOZ_TASK_ID') }, {'name': 'Instance ID', 'value': os.environ.get('BERLIOZ_INSTANCE_ID') }, {'name': 'Region', 'value': os.environ.get('BERLIOZ_REGION') } ] peers = berlioz.service('app').all() appPeer = {} try: response = berlioz.service('app').request().get('/') appPeer['title'] = 'RESPONSE:' appPeer['cardClass'] = 'eastern-blue' appPeer['response'] = response.text except Exception as ex: appPeer['title'] = 'ERROR:' appPeer['cardClass'] = 'red' appPeer['response'] = str(ex) return render_template('index.html', settings=settings, peers=peers, appPeer=appPeer)
def query_handler(): time.sleep(0.25) result = { 'message': 'Hello, my name is APP microservice. I have received following payload from BILL microservice.' } try: response = berlioz.service('bill').request().get('/') result['payload'] = response.text except Exception as ex: result['payload'] = str(ex) return json.dumps(result)
def form_example(): # return json.dumps(request.form) berlioz.service('api').request().post('/donate', data=request.form) return redirect("/", code=302)
def root(): # res = berlioz.service("app").all() res = berlioz.service("app").request().get('/') return res.text
def onAllPeersChanged(peers): berlioz.logger.info('**** onAllPeersChanged: %s', peers) berlioz.logger.info('**** random peer: %s', berlioz.service('app').random()) berlioz.logger.info('**** first peer: %s', berlioz.service('app').first()) berlioz.logger.info('**** all peers: %s', berlioz.service('app').all())
if __name__ == '__main__': import berlioz else: from . import berlioz def onAllPeersChanged(peers): berlioz.logger.info('**** onAllPeersChanged: %s', peers) berlioz.logger.info('**** random peer: %s', berlioz.service('app').random()) berlioz.logger.info('**** first peer: %s', berlioz.service('app').first()) berlioz.logger.info('**** all peers: %s', berlioz.service('app').all()) kuku = berlioz.service('app').monitorAll(onAllPeersChanged) def onFirstPeerChanged(peer): berlioz.logger.info('**** onFirstPeerChanged: %s', peer) kuku = berlioz.service('app').monitorFirst(onFirstPeerChanged) def onAllDatabasePeersChanged(peers): berlioz.logger.info('**** onAllDatabasePeersChanged: %s', peers) berlioz.logger.info('**** random database peer: %s', berlioz.database('contacts').random()) berlioz.logger.info('**** first database peer: %s', berlioz.database('contacts').first())