本文整理汇总了Python中cocaine.worker.Worker类的典型用法代码示例。如果您正苦于以下问题:Python Worker类的具体用法?Python Worker怎么用?Python Worker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Worker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: len
if len(tagging) > 0:
html += """
<h2>%s ---> %s</h2>
""" % (str(message.split()), str(tagging))
html += """
<form name="submitform" method="get" onSubmit="window.location.replace('/?message=' + document.submitform['sentence'])">
Sentence: <input type="text" name="message"><br>
<input type="submit" value="Tag!">
</form>
"""
html += """
Please, send your suggestions to: [email protected]
</body>
</html>
"""
# message = "i love birds"
# response.write(str(message) + " " + str(tagging))
response.write(html)
response.close()
W = Worker()
W.run({
'posTag': main,
})
# test()
示例2: Logger
#!/usr/bin/env python
import msgpack
from cocaine.decorators import http
from cocaine.worker import Worker
from cocaine.logging import Logger
__author__ = 'EvgenySafronov <[email protected]>'
log = Logger()
def echo(request, response):
message = yield request.read()
log.debug('Message received: \'{0}\'. Sending it back ...'.format(message))
response.write(msgpack.dumps(message))
response.close()
W = Worker()
W.run({
'doIt': echo,
})
示例3: Logger
#!/usr/bin/env python
import msgpack
from cocaine.worker import Worker
from cocaine.logging import Logger
__author__ = 'EvgenySafronov <[email protected]>'
log = Logger()
def chunker(request, response):
chunks = yield request.read()
try:
chunks = int(msgpack.loads(chunks))
except ValueError:
chunks = int(chunks)
for num in xrange(chunks):
response.write(msgpack.dumps('{0:-<1024}'.format(num)))
response.write(msgpack.dumps('Done'))
response.close()
W = Worker()
W.run({'chunkMe': chunker})
示例4: api
# users
"user-exists": user_exists,
"user-signup": user_signup,
"user-signin": user_signin,
"user-remove": user_remove,
"user-list": user_list,
"user-upload": user_upload,
"user-app-list": user_apps_list,
"user-buildlog-list": user_buildlog_list,
"user-buildlog-read": user_buildlog_read,
# app
"app-info": app_info,
"app-deploy": app_deploy,
"app-start": app_start,
"app-stop": app_stop,
}
API = {"Version": 1,
"Methods": binds.keys()}
def api(request, response):
yield request.read()
response.write(API)
response.close()
if __name__ == '__main__':
W = Worker()
W.on("API", api)
W.run(binds)
示例5: LoggerHandler
#!/usr/bin/env python
import logging
import os
from cocaine.decorators.wsgi import django
from cocaine.logging import LoggerHandler
from cocaine.worker import Worker
__author__ = 'Evgeny Safronov <[email protected]>'
PROJECT_NAME = 'enterprise'
log = logging.getLogger(__name__)
cocaineHandler = LoggerHandler()
log.addHandler(cocaineHandler)
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
worker = Worker()
worker.run({
'work': django(**{
'root': os.path.join(PROJECT_ROOT, PROJECT_NAME),
'settings': '{0}.settings'.format(PROJECT_NAME),
'async': True,
'log': log
})
})
示例6: main
#!/usr/bin/env python
import msgpack
from cocaine.decorators import http
from cocaine.worker import Worker
from cocaine.logging import Logger
@http
def main(request, response):
response.write_head(200, [("Content-Type", "plain/text")])
response.write("Hello, world!")
response.close()
W = Worker()
W.run({
'doIt': main,
})
示例7: Logger
# by the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Cocaine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from cocaine.worker import Worker
from cocaine.logging import Logger
__author__ = 'EvgenySafronov <[email protected]>'
log = Logger()
def echo(request, response):
message = yield request.read()
log.debug('Message received: \'{0}\'. Sending it back ...'.format(message))
response.write(message)
response.close()
W = Worker()
W.run({
'ping': echo,
})
示例8: write
def write(request, response):
data = yield request.read()
try:
channel = yield storage.write(NAMESPACE, KEY, data, [])
yield channel.rx.get()
response.write("Ok")
except Exception as err:
response.error(-100, repr(err))
finally:
response.close()
def read(request, response):
try:
channel = yield storage.read(NAMESPACE, KEY)
data = yield channel.rx.get()
response.write(data)
except Exception as err:
response.error(-100, repr(err))
finally:
response.close()
if __name__ == '__main__':
W = Worker()
W.run({"write": write,
"read": read,
"http": wsgi(app)})
示例9: len
except Exception as err:
logger.error("unable to aggreagate all: %s %s", name, err)
logger.info("name %s ALL %s %d" % (name, res, len(all_data)))
result[name][metahost] = res
# Send data to various senders
for name, item in aggcfg.senders.iteritems():
try:
sender_type = item.get("type")
if sender_type is None:
logger.error("unable to detect sender type: %s", name)
continue
logger.info("Send to %s", sender_type)
s = Service(sender_type)
res = yield s.enqueue("send", msgpack.packb({"Config": item,
"Data": result,
"Id": task.Id}))
logger.info("res for %s is %s", sender_type, res)
except Exception as err:
logger.error("unable to send to %s %s", name, err)
logger.info("Result %s", result)
response.write("Done")
response.close()
if __name__ == "__main__":
W = Worker()
W.run({"handleTask": aggreagate})
示例10: MySqlDG
log.info("Put data into %s" % tablename)
try:
m = MySqlDG(**config)
m.putData(data, tablename)
except Exception as err:
response.error(-100, str(err))
else:
response.write(tablename)
response.close()
def drop(request, response):
raw = yield request.read()
config, tablename = msgpack.unpackb(raw)
try:
m = MySqlDG(**config)
drop_query = "DROP TABLE IF EXISTS %s" % tablename
log.info(drop_query)
m.perfomCustomQuery(drop_query)
except Exception as err:
response.error(-100, str(err))
else:
response.write("ok")
response.close()
if __name__ == "__main__":
W = Worker()
W.run({"put": put,
"drop": drop})
示例11: future
L.info(error)
future = urlfetcher_service.get("www.ya.ru",{}, True)
future(on_url)
L.info("INITIALIZE FUNCTION")
future = urlfetcher_service.get()
future(on_url, errorback)
@http
def http(request, response):
stat = yield request.read()
L.info("HTTP")
L.info(stat)
response.write_head(200, [('Content-type', 'text/plain')])
response.write("OK")
response.close()
@fs
def fs(request, response):
stat = yield request.read()
L.info("FS")
L.info(stat)
response.write("OK")
response.close()
W = Worker()
#W.on("hash", example)
#W.on("nodejs", nodejs)
#W.on("fs", fs)
W.run({"hash" : example, "fs" : fs})
示例12: main
def main():
w = Worker()
w.on("ping", echo)
w.run()
示例13: Worker
#!/usr/bin/env python
import asyncio
from cocaine.worker import Worker
from cocaine.services import Service
w = Worker(app="app", uuid="a", endpoint="enp",
heartbeat_timeout=2, disown_timeout=1)
node = Service("node", version=0)
@asyncio.coroutine
def echo(request, response):
yield asyncio.sleep(1)
inp = yield request.read(timeout=1)
print inp
fut = yield node.list()
result = yield fut.get()
print result
response.write(result)
response.close()
w.on("echo", echo)
w.run()
示例14: main
def main():
log.info("entire main()")
w = Worker()
log.info("do main().Worker()")
w.run({"http": echo})
示例15: repr
response.error(-100, "There's no class named %s" % klass_name)
logger.error("class %s is absent", klass_name)
except Exception as err:
logger.error("%s", err)
response.error(100, repr(err))
else:
logger.info("Result of group aggreagtion %s", str(result))
response.write(result)
response.close()
def _aggregate_host(klass_name, payload, config, task):
available = plugin_import()
klass = available[klass_name]
handler = klass(config)
prevtime, currtime = task["prevtime"], task["currtime"]
return handler.aggregate_host(payload, prevtime, currtime)
def _aggregate_group(klass_name, payload, config):
available = plugin_import()
klass = available[klass_name]
handler = klass(config)
return handler.aggregate_group(payload)
if __name__ == '__main__':
W = Worker()
W.run({"aggregate_host": aggregate_host,
"aggregate_group": aggregate_group})