-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerState.py
More file actions
36 lines (28 loc) · 1.01 KB
/
Copy pathServerState.py
File metadata and controls
36 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import WorkUnit
import DistributableTask
class ServerState():
"""Captures the state of the server, such as what data needs processing"""
def __init__(self):
self.processed = 0
self.activeTasks = []
self.completedTasks = []
self.results = []
def aggregateResults(self, data):
self.results.extend(list(map(int, data)))
def nextWorkUnit(self):
tasks = list(filter(lambda x:x.finishedWorkers < 3, self.activeTasks))
if len(tasks) == 0:
nextTask = self.generateWorkUnit()
else:
nextTask = sorted(tasks, key=lambda x:x.finishedWorkers)[0].task
return nextTask
def displayData(self):
return str(self.results)
def generateWorkUnit(self):
start = self.processed
self.processed += 10
end = self.processed
newUnit = WorkUnit.WorkUnit(start, end)
newTask = DistributableTask.DistributableTask(newUnit)
self.activeTasks.append(newTask)
return newUnit