Last active
December 29, 2015 09:59
-
-
Save chao-he/7654281 to your computer and use it in GitHub Desktop.
beanstalk client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python26 | |
import sys | |
from tornado import ioloop | |
from tornado.options import define,options,parse_command_line | |
from beanstalkt import Client as BeansClient | |
define("bs_host", default="localhost") | |
define("bs_port", default=11300) | |
define("using", default="input") | |
def main(client): | |
def push(data): | |
data = sys.stdin.readline() | |
if data: | |
client.put(data.strip(), ttr=600, callback=push) | |
else: | |
ioloop.IOLoop.instance().stop() | |
client.connect(lambda: client.use(options.using, push)) | |
ioloop.IOLoop.instance().start() | |
if __name__ == "__main__": | |
parse_command_line() | |
client = BeansClient(options.bs_host, options.bs_port) | |
main(client) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment