This repository has been archived by the owner on Mar 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a236107
commit d52f611
Showing
5 changed files
with
129 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,6 @@ _site | |
apps | ||
__cache__ | ||
*.png | ||
.eggs | ||
.cache | ||
AUTHORS |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# taskqueue | ||
instruments与外部的交互 | ||
|
||
## 需要实现的功能 | ||
1. get | ||
2. done | ||
3. put | ||
|
||
``` | ||
$ python -matx.taskqueue --room ${UDID} put '{id: "12", result: true, action: "target.click(10, 20)"}' | ||
Success | ||
$ python -matx.taskqueue --room ${UDID} get | ||
{id: "12", result: true, action: "target.click(10, 20)"} | ||
$ python -matx.taskqueue --room ${UDID} done '{id: "12", result: "1234551"}' | ||
Success | ||
``` | ||
|
||
Or use api to call | ||
|
||
``` | ||
import atx.taskqueue as tqueue | ||
result = tqueue.put(udid, action='target.click(10, 10)', result=True) | ||
print result | ||
``` | ||
|
||
expect | ||
|
||
"ok" |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import uuid | ||
|
||
import tornado.web | ||
import tornado.escape | ||
from tornado import gen | ||
from tornado.ioloop import IOLoop | ||
from tornado.queues import Queue | ||
|
||
|
||
# @gen.coroutine | ||
# def consumer(): | ||
# while True: | ||
# item = yield que.get() | ||
# try: | ||
# print('Doing work on %s' % item) | ||
# yield gen.sleep(0.5) | ||
# finally: | ||
# que.task_done() | ||
|
||
# @gen.coroutine | ||
# def producer(): | ||
# for item in range(5): | ||
# yield que.put(item) | ||
# print('Put %s' % item) | ||
|
||
# @gen.coroutine | ||
# def main(): | ||
# # Start consumer without waiting (since it never finishes). | ||
# IOLoop.current().spawn_callback(consumer) | ||
# yield producer() # Wait for producer to put all tasks. | ||
# yield que.join() # Wait for consumer to finish all tasks. | ||
# print('Done') | ||
|
||
|
||
class MainHandler(tornado.web.RequestHandler): | ||
que = Queue(maxsize=2) | ||
results = {} | ||
|
||
@gen.coroutine | ||
def get(self, udid): | ||
''' get new task ''' | ||
item = yield self.que.get() | ||
print udid, item | ||
self.que.task_done() | ||
self.write(item) | ||
self.finish() | ||
|
||
@gen.coroutine | ||
def post(self, udid): | ||
''' add new task ''' | ||
# print self.request.body | ||
data = tornado.escape.json_decode(self.request.body) | ||
data['id'] = str(uuid.uuid1()) | ||
print data | ||
yield self.que.put(data) | ||
self.write({'id': data['id']}) | ||
self.finish() | ||
|
||
def put(self, udid): | ||
''' finish task ''' | ||
data = tornado.escape.json_decode(self.request.body) | ||
print data['id'] | ||
print data['result'] | ||
|
||
|
||
def make_app(**settings): | ||
print settings | ||
return tornado.web.Application([ | ||
(r"/rooms/([^/]*)", MainHandler), | ||
], **settings) | ||
|
||
|
||
if __name__ == '__main__': | ||
app = make_app(debug=True) | ||
app.listen(10020) | ||
IOLoop.current().start() #run_sync(main) |