introduce priority system

This commit is contained in:
JerryXiao 2019-10-01 17:36:49 +08:00
parent 9451a8e79e
commit 7bf67bc21f
2 changed files with 7 additions and 3 deletions

View File

@ -67,6 +67,8 @@ class Job:
ret += f'{myproperty}={getattr(self, myproperty, None)},' ret += f'{myproperty}={getattr(self, myproperty, None)},'
ret += ')' ret += ')'
return ret return ret
def __lt__(self, job2):
return self.pkgconfig.priority < job2.pkgconfig.priority
class jobsManager: class jobsManager:
def __init__(self): def __init__(self):
self.__buildjobs = list() self.__buildjobs = list()
@ -186,6 +188,7 @@ class jobsManager:
return self.__get_job() return self.__get_job()
jobs = self.__buildjobs jobs = self.__buildjobs
if jobs: if jobs:
jobs.sort(reverse=True)
self.__curr_job = jobs.pop(0) self.__curr_job = jobs.pop(0)
return self.__curr_job return self.__curr_job
def __finish_job(self, pkgdir, force=False): def __finish_job(self, pkgdir, force=False):

View File

@ -20,7 +20,7 @@ os.chdir(abspath)
REPO_ROOT = Path(PKGBUILD_DIR) REPO_ROOT = Path(PKGBUILD_DIR)
class pkgConfig: class pkgConfig:
def __init__(self, dirname, pkgtype, cleanbuild, timeout, extra): def __init__(self, dirname, pkgtype, cleanbuild, timeout, priority, extra):
self.dirname = dirname self.dirname = dirname
self.type = pkgtype self.type = pkgtype
@ -33,6 +33,7 @@ class pkgConfig:
self.timeout = 30 if timeout is None else int(timeout) self.timeout = 30 if timeout is None else int(timeout)
# timeout in minutes # timeout in minutes
self.priority = 0 if priority is None else int(priority)
self.__extra = extra self.__extra = extra
self.__process_extra() self.__process_extra()
@ -62,7 +63,7 @@ class pkgConfig:
ret = "pkgConfig(" ret = "pkgConfig("
for myproperty in \ for myproperty in \
( (
'dirname', 'type', 'cleanbuild', 'timeout', 'dirname', 'type', 'cleanbuild', 'timeout', 'priority',
'prebuild', 'postbuild', 'update', 'failure' 'prebuild', 'postbuild', 'update', 'failure'
): ):
ret += f'{myproperty}={getattr(self, myproperty, None)},' ret += f'{myproperty}={getattr(self, myproperty, None)},'
@ -82,7 +83,7 @@ def load_all():
content = load(content, Loader=Loader) content = load(content, Loader=Loader)
assert type(content) is dict assert type(content) is dict
args = [content.get(part, None) for part in \ args = [content.get(part, None) for part in \
('type', 'cleanbuild', 'timeout', 'extra')] ('type', 'cleanbuild', 'timeout', 'priority', 'extra')]
args = [mydir.name] + args args = [mydir.name] + args
pkgconfigs.append(pkgConfig(*args)) pkgconfigs.append(pkgConfig(*args))
else: else: