-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.py
76 lines (66 loc) · 2.19 KB
/
job.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from task import *
# a job is an instance of a task
class Job:
def __init__(self, task: Task, act_time: int) -> None:
self.uuid = uuid.uuid4() # job unique id
self.task = task # task info
self.act_time = act_time # absolute act time
self.ADeadline = task.deadline + act_time # absolute
self.deadline = task.deadline # relative
self.wcet = task.wcet # worst case execution time
self.type = task.type # type
self.period = task.period # period - just for easier access
self.priority = task.priority # priority
# uptime is used to find how much of a task has been executed
self.uptime = 0
self.state = task.state
# set section
self.section = task.section
# increase on step of time on this task
def increase_uptime(self):
if self.state != RUNNING:
return -1 # suspended or ready
if self.uptime < self.wcet:
self.uptime += 1
if self.uptime == self.wcet:
self.state = COMPLETED
return 0
else:
return 1 # completed
# returns state of task
def get_state(self):
return self.state
# set state of task
def set_state(self, new_state):
if self.state == COMPLETED:
return -1
else:
self.state = new_state
return 0
# return state of task
def is_complete(self):
if self.state == COMPLETED:
return True
return False
# tells if a deadline is missed
def is_deadline_missed(self, cpu_time):
if self.state != COMPLETED and cpu_time >= self.ADeadline:
return True
return False
# return name of task
def get_name(self):
return self.task.name
# return priority of task
def get_priority(self):
return self.task.priority
# returns task section ID
def get_section(self):
if len(self.section) < 1:
return 0
up = 0
for part in self.section:
up += part[1]
if self.uptime < up:
return part[0]
print('section declaration error')
return 0