]>
git.ipfire.org Git - people/jschlag/pbs.git/blob - src/manager/builds.py
9ff85d2bc58d8ca26d1433dd6919b04b5f9495cd
15 from ..constants
import *
17 class BuildsFailedRestartEvent(base
.Event
):
23 return self
.pakfire
.settings
.get_int("build_keepalive_interval", 900)
26 max_tries
= self
.pakfire
.settings
.get_int("builds_restart_max_tries", 9)
28 query
= self
.db
.query("SELECT jobs.id AS id FROM jobs \
29 JOIN builds ON builds.id = jobs.build_id \
31 jobs.type = 'build' AND \
32 jobs.state = 'failed' AND \
33 jobs.tries <= %s AND \
34 NOT builds.state = 'broken' AND \
35 jobs.time_finished < NOW() - '72 hours'::interval \
38 WHEN jobs.type = 'build' THEN 0 \
39 WHEN jobs.type = 'test' THEN 1 \
41 builds.priority DESC, jobs.time_created ASC",
45 job
= self
.pakfire
.jobs
.get_by_id(row
.id)
48 job
.set_state("new", log
=False)
51 class CheckBuildDependenciesEvent(base
.Event
):
52 # Process them as quickly as possible, but there may be more important events.
57 return self
.pakfire
.settings
.get_int("dependency_checker_interval", 30)
60 query
= self
.db
.query("SELECT id FROM jobs \
61 WHERE state = 'new' OR \
62 (state = 'dependency_error' AND \
63 time_finished < NOW() - '5 minutes'::interval) \
64 ORDER BY time_finished LIMIT 50")
67 e
= CheckBuildDependencyEvent(self
.pakfire
, row
.id)
68 self
.scheduler
.add_event(e
)
71 class CheckBuildDependencyEvent(base
.Event
):
72 # Process them as quickly as possible, but there may be more important events.
75 def run(self
, job_id
):
76 self
.run_subprocess(self
._run
, job_id
)
79 def _run(_pakfire
, job_id
):
80 # Get the build job we are working on.
81 job
= _pakfire
.jobs
.get_by_id(job_id
)
83 logging
.debug("Job %s does not exist." % job_id
)
86 # Check if the job status has changed in the meanwhile.
87 if not job
.state
in ("new", "dependency_error", "failed"):
88 logging
.warning("Job status has already changed: %s - %s" % (job
.name
, job
.state
))
91 # Resolve the dependencies.
95 class DistEvent(base
.Event
):
102 self
.first_run
= False
104 self
.process
= self
.init_repos()
106 for commit
in self
.pakfire
.sources
.get_pending_commits():
107 commit
.state
= "running"
109 logging
.debug("Processing commit %s: %s" % (commit
.revision
, commit
.subject
))
111 # Get the repository of this commit.
112 repo
= git
.Repo(self
.pakfire
, commit
.source
)
114 # Make sure, it is checked out.
118 # Navigate to the right revision.
119 repo
.checkout(commit
.revision
)
121 # Get all changed makefiles.
125 for file in repo
.changed_files(commit
.revision
):
126 # Don't care about files that are not a makefile.
127 if not file.endswith(".%s" % MAKEFILE_EXTENSION
):
130 if os
.path
.exists(file):
131 updated_files
.append(file)
133 deleted_files
.append(file)
135 e
= DistFileEvent(self
.pakfire
, None, commit
.id, updated_files
, deleted_files
)
136 self
.scheduler
.add_event(e
)
138 def init_repos(self
):
140 Initialize all repositories.
142 for source
in self
.pakfire
.sources
.get_all():
143 # Skip those which already have a revision.
147 # Initialize the repository or and clone it if necessary.
148 repo
= git
.Repo(self
.pakfire
, source
)
152 # Get a list of all files in the repository.
153 files
= repo
.get_all_files()
155 for file in [f
for f
in files
if file.endswith(".%s" % MAKEFILE_EXTENSION
)]:
156 e
= DistFileEvent(self
.pakfire
, source
.id, None, [file,], [])
157 self
.scheduler
.add_event(e
)
160 class DistFileEvent(base
.Event
):
161 def run(self
, *args
):
162 self
.run_subprocess(self
._run
, *args
)
165 def _run(_pakfire
, source_id
, commit_id
, updated_files
, deleted_files
):
170 commit
= _pakfire
.sources
.get_commit_by_id(commit_id
)
173 source
= commit
.source
175 if source_id
and not source
:
176 source
= _pakfire
.sources
.get_by_id(source_id
)
181 # Create a temporary directory where to put all the files
182 # that are generated here.
183 pkg_dir
= tempfile
.mkdtemp()
186 config
= pakfire
.config
.Config(["general.conf",])
187 config
.parse(source
.distro
.get_config())
189 p
= pakfire
.PakfireServer(config
=config
)
192 for file in updated_files
:
194 pkg_file
= p
.dist(file, pkg_dir
)
195 pkgs
.append(pkg_file
)
199 # Import all packages in one swoop.
201 # Import the package file and create a build out of it.
202 builds
.import_from_package(_pakfire
, pkg
,
203 distro
=source
.distro
, commit
=commit
, type="release")
207 commit
.state
= "failed"
212 if os
.path
.exists(pkg_dir
):
213 shutil
.rmtree(pkg_dir
)
215 for file in deleted_files
:
216 # Determine the name of the package.
217 name
= os
.path
.basename(file)
218 name
= name
[:len(MAKEFILE_EXTENSION
) + 1]
220 source
.distro
.delete_package(name
)
223 commit
.state
= "finished"