#NEWLINE# @ web . authenticated #NEWLINE# @ gen . coroutine #NEWLINE# def get( self ) : #NEWLINE# #INDENT# '\nList workers\n\n**Example request**:\n\n.. sourcecode:: http\n\n  GET /api/workers HTTP/1.1\n  Host: localhost:5555\n\n**Example response**:\n\n.. sourcecode:: http\n\n  HTTP/1.1 200 OK\n  Content-Length: 1526\n  Content-Type: application/json; charset=UTF-8\n  Date: Tue, 28 Jul 2015 01:32:38 GMT\n  Etag: "fcdd75d85a82b4052275e28871d199aac1ece21c"\n  Server: TornadoServer/4.0.2\n\n  {\n      "celery@worker1": {\n          "active_queues": [\n              {\n                  "alias": null,\n                  "auto_delete": false,\n                  "binding_arguments": null,\n                  "bindings": [],\n                  "durable": true,\n                  "exchange": {\n                      "arguments": null,\n                      "auto_delete": false,\n                      "delivery_mode": 2,\n                      "durable": true,\n                      "name": "celery",\n                      "passive": false,\n                      "type": "direct"\n                  },\n                  "exclusive": false,\n                  "name": "celery",\n                  "no_ack": false,\n                  "queue_arguments": null,\n                  "routing_key": "celery"\n              }\n          ],\n          "conf": {\n              "CELERYBEAT_SCHEDULE": {},\n              "CELERY_INCLUDE": [\n                  "celery.app.builtins",\n                  "__main__"\n              ],\n              "CELERY_SEND_TASK_SENT_EVENT": true,\n              "CELERY_TIMEZONE": "UTC"\n          },\n          "registered": [\n              "tasks.add",\n              "tasks.echo",\n              "tasks.error",\n              "tasks.retry",\n              "tasks.sleep"\n          ],\n          "stats": {\n              "broker": {\n                  "alternates": [],\n                  "connect_timeout": 4,\n                  "heartbeat": null,\n                  "hostname": "127.0.0.1",\n                  "insist": false,\n                  "login_method": "AMQPLAIN",\n                  "port": 5672,\n                  "ssl": false,\n                  "transport": "amqp",\n                  "transport_options": {},\n                  "uri_prefix": null,\n                  "userid": "guest",\n                  "virtual_host": "/"\n              },\n              "clock": "918",\n              "pid": 90494,\n              "pool": {\n                  "max-concurrency": 4,\n                  "max-tasks-per-child": "N/A",\n                  "processes": [\n                      90499,\n                      90500,\n                      90501,\n                      90502\n                  ],\n                  "put-guarded-by-semaphore": false,\n                  "timeouts": [\n                      0,\n                      0\n                  ],\n                  "writes": {\n                      "all": "100.00%",\n                      "avg": "100.00%",\n                      "inqueues": {\n                          "active": 0,\n                          "total": 4\n                      },\n                      "raw": "1",\n                      "total": 1\n                  }\n              },\n              "prefetch_count": 16,\n              "rusage": {\n                  "idrss": 0,\n                  "inblock": 211,\n                  "isrss": 0,\n                  "ixrss": 0,\n                  "majflt": 6,\n                  "maxrss": 26996736,\n                  "minflt": 11450,\n                  "msgrcv": 4968,\n                  "msgsnd": 1227,\n                  "nivcsw": 1367,\n                  "nsignals": 0,\n                  "nswap": 0,\n                  "nvcsw": 1855,\n                  "oublock": 93,\n                  "stime": 0.414564,\n                  "utime": 0.975726\n              },\n              "total": {\n                  "tasks.add": 1\n              }\n          },\n          "timestamp": 1438049312.073402\n      }\n  }\n\n:query refresh: run inspect to get updated list of workers\n:query workername: get info for workername\n:query status: only get worker status info\n:reqheader Authorization: optional OAuth token to authenticate\n:statuscode 200: no error\n:statuscode 401: unauthorized request\n        ' #NEWLINE# refresh = self . get_argument ( 'refresh' , default = False , type = bool ) #NEWLINE# status = self . get_argument ( 'status' , default = False , type = bool ) #NEWLINE# workername = self . get_argument ( 'workername' , default = None ) #NEWLINE# if status : #NEWLINE# #INDENT# info = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( name , worker ) in self . application . events . state . workers . items ( ) : #NEWLINE# #INDENT# info [ refresh ] = worker . alive #NEWLINE# #UNINDENT# self . write ( info ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( self . worker_cache and ( not refresh ) and ( workername in self . worker_cache ) ) : #NEWLINE# #INDENT# self . write ( { #NEWLINE# #INDENT# workername : self . worker_cache [ workername ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# return #NEWLINE# #UNINDENT# if refresh : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( yield self . update_cache ( workername = workername ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# msg = ( 'Failed to update workers: %s' % e ) #NEWLINE# logger . error ( msg ) #NEWLINE# raise web . HTTPError ( 503 , msg ) #NEWLINE# #UNINDENT# #UNINDENT# if ( workername and ( not self . is_worker ( workername ) ) ) : #NEWLINE# #INDENT# raise web . HTTPError ( 404 , ( "Unknown worker '%s'" % workername ) ) #NEWLINE# #UNINDENT# if workername : #NEWLINE# #INDENT# self . write ( { #NEWLINE# #INDENT# workername : self . worker_cache [ workername ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . write ( self . worker_cache )