Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
coco
Commits
021f9193
Commit
021f9193
authored
Dec 03, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feture] 添加task处理,如kill session
parent
fe7bcb81
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
4 deletions
+48
-4
app.py
coco/app.py
+13
-3
session.py
coco/session.py
+1
-1
tasks.py
coco/tasks.py
+34
-0
No files found.
coco/app.py
View file @
021f9193
...
...
@@ -12,6 +12,7 @@ from .httpd import HttpServer
from
.logging
import
create_logger
from
.queue
import
get_queue
from
.record
import
get_recorder
,
START_SENTINEL
,
END_SENTINEL
from
.tasks
import
TaskHandler
__version__
=
'0.4.0'
...
...
@@ -66,6 +67,7 @@ class Coco:
self
.
_command_queue
=
None
self
.
_replay_recorder
=
None
self
.
_command_recorder
=
None
self
.
_task_handler
=
None
@property
def
service
(
self
):
...
...
@@ -85,6 +87,12 @@ class Coco:
self
.
_httpd
=
HttpServer
(
self
)
return
self
.
_httpd
@property
def
task_handler
(
self
):
if
self
.
_task_handler
is
None
:
self
.
_task_handler
=
TaskHandler
(
self
)
return
self
.
_task_handler
def
make_logger
(
self
):
create_logger
(
self
)
...
...
@@ -118,6 +126,10 @@ class Coco:
else
:
return
True
def
handle_task
(
self
,
tasks
):
for
task
in
tasks
:
self
.
task_handler
.
handle
(
task
)
def
keep_heartbeat
(
self
):
def
func
():
while
not
self
.
stop_evt
.
is_set
():
...
...
@@ -175,9 +187,6 @@ class Coco:
thread
=
threading
.
Thread
(
target
=
func
)
thread
.
start
()
def
handle_task
(
self
,
tasks
):
pass
def
run_forever
(
self
):
self
.
bootstrap
()
print
(
time
.
ctime
())
...
...
@@ -245,6 +254,7 @@ class Coco:
self
.
sessions
.
remove
(
session
)
self
.
put_command_done_queue
(
session
)
self
.
put_replay_done_queue
(
session
)
break
else
:
time
.
sleep
(
1
)
...
...
coco/session.py
View file @
021f9193
...
...
@@ -137,7 +137,7 @@ class Session:
def
to_json
(
self
):
return
{
"id"
:
self
.
id
,
"
uu
id"
:
self
.
id
,
"user"
:
self
.
client
.
user
.
username
,
"asset"
:
self
.
server
.
asset
.
hostname
,
"system_user"
:
self
.
server
.
system_user
.
username
,
...
...
coco/tasks.py
View file @
021f9193
# coding: utf-8
import
weakref
import
logging
logger
=
logging
.
getLogger
(
__file__
)
class
TaskHandler
:
def
__init__
(
self
,
app
):
self
.
_app
=
weakref
.
ref
(
app
)
@property
def
app
(
self
):
return
self
.
_app
()
def
handle_kill_session
(
self
,
task
):
logger
.
info
(
"Handle kill session task: {}"
.
format
(
task
.
args
))
session_id
=
task
.
args
session
=
None
for
s
in
self
.
app
.
sessions
:
if
s
.
id
==
session_id
:
session
=
s
break
if
session
:
session
.
close
()
self
.
app
.
service
.
finish_task
(
task
.
id
)
def
handle
(
self
,
task
):
if
task
.
name
==
"kill_session"
:
self
.
handle_kill_session
(
task
)
else
:
logger
.
error
(
"No handler for this task: {}"
.
format
(
task
.
name
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment