Esempio n. 1
0
 def getService(self, name):
     try:
         service = Service(name, blockingConnect=False)
         service.connectThroughLocator(self.locator, self.timeout, blocking=True)
         return service
     except Exception as err:
         raise ToolsError(err)
Esempio n. 2
0
    def execute(self):
        log.info('Checking "%s"... ', self.name)
        apps = yield List(self.storage).execute()
        if self.name not in apps:
            raise ToolsError('not available')

        app = Service(self.name, blockingConnect=False)
        try:
            yield app.connectThroughLocator(self.locator)
            info = yield app.info()
            log.info(info['state'])
        except (LocatorResolveError, ServiceError):
            raise ToolsError('stopped')
Esempio n. 3
0
def apps(request):
    node = Service('node')
    list_ = yield node.list()
    yield render(request, 'list.html', {
        'apps': list_
    })
import json
import time

from cocaine.asio.service import Service

__author__ = 'Evgeny Safronov <[email protected]>'


__doc__ = '''ELASTICSEARCH SERVICE USAGE EXAMPLE.
Elasticsearch must be started. Also elasticsearch cocaine plugin must be properly configured.
'''

now = time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime(time.time()))

elastic = Service('elasticsearch')

##### INDEX #####
print('Index simple message with index "/twitter/tweet/1"')
data = {
    'user': '3Hren',
    'post_date': now,
    'message': 'Hello, Elasticsearch!'
}
print('Result:', elastic.index(json.dumps(data), 'twitter', 'tweet', '1').get())
print('')

##### GET #####
print('And now get it')
print(elastic.get('twitter', 'tweet', '1').get())
print('')