当前位置: 首页>>代码示例>>Python>>正文


Python Worker.run方法代码示例

本文整理汇总了Python中cocaine.worker.Worker.run方法的典型用法代码示例。如果您正苦于以下问题:Python Worker.run方法的具体用法?Python Worker.run怎么用?Python Worker.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cocaine.worker.Worker的用法示例。


在下文中一共展示了Worker.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: len

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
    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()
开发者ID:akashin,项目名称:cocaine_app,代码行数:32,代码来源:pos_tag.py

示例2: Logger

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
#!/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,
})
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:25,代码来源:echo.py

示例3: Logger

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
#!/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})
开发者ID:devlato,项目名称:cocaine-framework-python,代码行数:27,代码来源:chunker.py

示例4: api

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
    # 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)
开发者ID:biinilya,项目名称:cocaine-flow,代码行数:32,代码来源:flow-tools.py

示例5: LoggerHandler

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
#!/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
    })
})
开发者ID:devlato,项目名称:cocaine-framework-python,代码行数:30,代码来源:slave.py

示例6: main

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
#!/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,
})
开发者ID:akashin,项目名称:cocaine_app,代码行数:22,代码来源:hello.py

示例7: Logger

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
#    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,
})
开发者ID:3Hren,项目名称:cocaine-paper-sources,代码行数:33,代码来源:echo.py

示例8: write

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]

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)})
开发者ID:antmat,项目名称:cocaine-framework-python,代码行数:31,代码来源:main.py

示例9: len

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
        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})
开发者ID:gitter-badger,项目名称:Combaine,代码行数:32,代码来源:aggregate_core.py

示例10: MySqlDG

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
    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})
开发者ID:kartvep,项目名称:Combaine,代码行数:32,代码来源:mysqldg.py

示例11: future

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
        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})
开发者ID:devlato,项目名称:cocaine-framework-python,代码行数:32,代码来源:async_service_and_dealer.py

示例12: main

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
def main():
    w = Worker()
    w.on("ping", echo)
    w.run()
开发者ID:antmat,项目名称:cocaine-framework-python,代码行数:6,代码来源:__init__.py

示例13: Worker

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
#!/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()
开发者ID:rmoorman,项目名称:cocaine-framework-python,代码行数:29,代码来源:w.py

示例14: main

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
def main():
    log.info("entire main()")
    w = Worker()
    log.info("do main().Worker()")
    w.run({"http": echo})
开发者ID:borislitv,项目名称:echo,代码行数:7,代码来源:echo.py

示例15: repr

# 需要导入模块: from cocaine.worker import Worker [as 别名]
# 或者: from cocaine.worker.Worker import run [as 别名]
        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})
开发者ID:gitter-badger,项目名称:Combaine,代码行数:32,代码来源:custom.py


注:本文中的cocaine.worker.Worker.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。