Skip to content

Commit

Permalink
Add queue_time and start_time, to get more info on when a specific qu… (
Browse files Browse the repository at this point in the history
#6717)

* Add queue_time and start_time, to get more info on when a specific queue item was queued and started.

* Add save generic queue items in a FIFO queue.
This will replace the fifo queue used currently for the forced and backlog searches.
As a more generic approach.
  • Loading branch information
p0psicles authored and medariox committed Jun 10, 2019
1 parent 1fb0d2d commit 90691ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion medusa/generic_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class QueuePriorities(object):


class GenericQueue(object):
def __init__(self):
def __init__(self, max_history=100):
self.currentItem = None
self.queue = []
self.history = []
self.max_history = max_history
self.queue_name = 'QUEUE'
self.min_priority = 0
self.lock = threading.Lock()
Expand Down Expand Up @@ -95,6 +97,7 @@ def sorter(x, y):
item=self.currentItem.name,
)
self.currentItem.start()
fifo(self.history, self.currentItem, self.max_history)

self.amActive = False

Expand All @@ -108,12 +111,22 @@ def __init__(self, name, action_id=0):
self.action_id = action_id
self.stop = threading.Event()
self.added = None
self.queue_time = datetime.datetime.now()
self.start_time = None

def run(self):
"""Implementing classes should call this."""
self.inProgress = True
self.start_time = datetime.datetime.now()

def finish(self):
"""Implementing Classes should call this."""
self.inProgress = False
threading.currentThread().name = self.name


def fifo(my_list, item, max_size=100):
"""Append item to queue and limit it to 100 items."""
if len(my_list) >= max_size:
my_list.pop(0)
my_list.append(item)
2 changes: 2 additions & 0 deletions medusa/search/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def get_episodes(search_thread, searchstatus):
ep.status, ep.quality,
manually_searched=ep.manually_searched
)],
'queuetime': search_thread.queue_time.isoformat(),
'starttime': search_thread.start_time.isoformat() if search_thread.start_time else None,
})

return results
Expand Down

0 comments on commit 90691ab

Please sign in to comment.