Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
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
captainwong
douban-api-proxy
Commits
d406d918
Commit
d406d918
authored
Aug 30, 2020
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'worker/tasks' into Develop
parents
98494c61
e7eb5b6e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
17 deletions
+21
-17
worker.py
cps/services/worker.py
+21
-17
No files found.
cps/services/worker.py
View file @
d406d918
...
...
@@ -82,33 +82,37 @@ class WorkerThread(threading.Thread):
tasks
=
self
.
queue
.
to_list
()
+
self
.
dequeued
return
sorted
(
tasks
,
key
=
lambda
x
:
x
.
num
)
def
cleanup_tasks
(
self
):
with
self
.
doLock
:
dead
=
[]
alive
=
[]
for
x
in
self
.
dequeued
:
(
dead
if
x
.
task
.
dead
else
alive
)
.
append
(
x
)
# if the ones that we need to keep are within the trigger, do nothing else
delta
=
len
(
self
.
dequeued
)
-
len
(
dead
)
if
delta
>
TASK_CLEANUP_TRIGGER
:
ret
=
alive
else
:
# otherwise, lop off the oldest dead tasks until we hit the target trigger
ret
=
sorted
(
dead
,
key
=
lambda
x
:
x
.
task
.
end_time
)[
-
TASK_CLEANUP_TRIGGER
:]
+
alive
self
.
dequeued
=
sorted
(
ret
,
key
=
lambda
x
:
x
.
num
)
# Main thread loop starting the different tasks
def
run
(
self
):
main_thread
=
_get_main_thread
()
while
main_thread
.
is_alive
():
# this blocks until something is available
item
=
self
.
queue
.
get
()
with
self
.
doLock
:
# once we hit our trigger, start cleaning up dead tasks
if
len
(
self
.
dequeued
)
>
TASK_CLEANUP_TRIGGER
:
dead
=
[]
alive
=
[]
for
x
in
self
.
dequeued
:
(
dead
if
x
.
task
.
dead
else
alive
)
.
append
(
x
)
# if the ones that we need to keep are within the trigger, do nothing else
delta
=
len
(
self
.
dequeued
)
-
len
(
dead
)
if
delta
>
TASK_CLEANUP_TRIGGER
:
ret
=
alive
else
:
# otherwise, lop off the oldest dead tasks until we hit the target trigger
ret
=
sorted
(
dead
,
key
=
lambda
x
:
x
.
task
.
end_time
)[
-
TASK_CLEANUP_TRIGGER
:]
+
alive
self
.
dequeued
=
sorted
(
ret
,
key
=
lambda
x
:
x
.
num
)
# add to list so that in-progress tasks show up
self
.
dequeued
.
append
(
item
)
# once we hit our trigger, start cleaning up dead tasks
if
len
(
self
.
dequeued
)
>
TASK_CLEANUP_TRIGGER
:
self
.
cleanup_tasks
()
# sometimes tasks (like Upload) don't actually have work to do and are created as already finished
if
item
.
task
.
stat
is
STAT_WAITING
:
# CalibreTask.start() should wrap all exceptions in it's own error handling
...
...
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