refactor(build): remove some code duplication from queue
parent
03f2240ff6
commit
d3151863ee
|
@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
* Migrated codebase to V 0.3.2
|
* Migrated codebase to V 0.3.2
|
||||||
* Cron expression parser now uses bitfields instead of bool arrays
|
* Cron expression parser now uses bitfields instead of bool arrays
|
||||||
|
* Added option to deploy using agent-server architecture instead of cron daemon
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
* CLI no longer exits with non-zero status code when removing/patching
|
* CLI no longer exits with non-zero status code when removing/patching
|
||||||
target
|
target
|
||||||
* Allow NULL values for branch in database
|
* Allow NULL values for branch in database
|
||||||
|
* Endpoint for adding targets now returns the correct id
|
||||||
|
|
||||||
## [0.4.0](https://git.rustybever.be/vieter-v/vieter/src/tag/0.4.0)
|
## [0.4.0](https://git.rustybever.be/vieter-v/vieter/src/tag/0.4.0)
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ quicker.
|
||||||
I chose [V](https://vlang.io/) as I've been very intrigued by this language for
|
I chose [V](https://vlang.io/) as I've been very intrigued by this language for
|
||||||
a while now. I wanted a fast language that I could code while relaxing, without
|
a while now. I wanted a fast language that I could code while relaxing, without
|
||||||
having to exert too much mental effort & V seemed like the right choice for
|
having to exert too much mental effort & V seemed like the right choice for
|
||||||
that.
|
that. Sadly, this didn't quite turn out the way I expected, but I'm sticking
|
||||||
|
with it anyways ;p
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ update`.
|
||||||
|
|
||||||
I used to maintain a mirror that tracked the latest master, but nowadays, I
|
I used to maintain a mirror that tracked the latest master, but nowadays, I
|
||||||
maintain a Docker image containing the specific compiler version that Vieter
|
maintain a Docker image containing the specific compiler version that Vieter
|
||||||
builds with. Currently, this is V 0.3.
|
builds with. Currently, this is V 0.3.2.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,21 @@ fn (mut q BuildJobQueue) reschedule(job BuildJob, arch string) ! {
|
||||||
q.queues[arch].insert(new_job)
|
q.queues[arch].insert(new_job)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pop_invalid pops all invalid jobs.
|
||||||
|
fn (mut q BuildJobQueue) pop_invalid(arch string) {
|
||||||
|
for {
|
||||||
|
job := q.queues[arch].peek() or { return }
|
||||||
|
|
||||||
|
if job.config.target_id in q.invalidated
|
||||||
|
&& job.created < q.invalidated[job.config.target_id] {
|
||||||
|
// This pop *should* never fail according to the source code
|
||||||
|
q.queues[arch].pop() or {}
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// peek shows the first job for the given architecture that's ready to be
|
// peek shows the first job for the given architecture that's ready to be
|
||||||
// executed, if present.
|
// executed, if present.
|
||||||
pub fn (mut q BuildJobQueue) peek(arch string) ?BuildJob {
|
pub fn (mut q BuildJobQueue) peek(arch string) ?BuildJob {
|
||||||
|
@ -118,20 +133,11 @@ pub fn (mut q BuildJobQueue) peek(arch string) ?BuildJob {
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
q.pop_invalid(arch)
|
||||||
job := q.queues[arch].peek() or { return none }
|
job := q.queues[arch].peek()?
|
||||||
|
|
||||||
// Skip any invalidated jobs
|
if job.timestamp < time.now() {
|
||||||
if job.config.target_id in q.invalidated
|
return job
|
||||||
&& job.created < q.invalidated[job.config.target_id] {
|
|
||||||
// This pop *should* never fail according to the source code
|
|
||||||
q.queues[arch].pop() or { return none }
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if job.timestamp < time.now() {
|
|
||||||
return job
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,27 +152,18 @@ pub fn (mut q BuildJobQueue) pop(arch string) ?BuildJob {
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
q.pop_invalid(arch)
|
||||||
mut job := q.queues[arch].peek() or { return none }
|
mut job := q.queues[arch].peek()?
|
||||||
|
|
||||||
// Skip any invalidated jobs
|
if job.timestamp < time.now() {
|
||||||
if job.config.target_id in q.invalidated
|
job = q.queues[arch].pop()?
|
||||||
&& job.created < q.invalidated[job.config.target_id] {
|
|
||||||
// This pop *should* never fail according to the source code
|
|
||||||
q.queues[arch].pop() or { return none }
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if job.timestamp < time.now() {
|
// TODO how do we handle this properly? Is it even possible for a
|
||||||
job = q.queues[arch].pop()?
|
// cron expression to not return a next time if it's already been
|
||||||
|
// used before?
|
||||||
|
q.reschedule(job, arch) or {}
|
||||||
|
|
||||||
// TODO how do we handle this properly? Is it even possible for a
|
return job
|
||||||
// cron expression to not return a next time if it's already been
|
|
||||||
// used before?
|
|
||||||
q.reschedule(job, arch) or {}
|
|
||||||
|
|
||||||
return job
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,28 +179,19 @@ pub fn (mut q BuildJobQueue) pop_n(arch string, n int) []BuildJob {
|
||||||
|
|
||||||
mut out := []BuildJob{}
|
mut out := []BuildJob{}
|
||||||
|
|
||||||
outer: for out.len < n {
|
for out.len < n {
|
||||||
for {
|
q.pop_invalid(arch)
|
||||||
mut job := q.queues[arch].peek() or { break outer }
|
mut job := q.queues[arch].peek() or { break }
|
||||||
|
|
||||||
// Skip any invalidated jobs
|
if job.timestamp < time.now() {
|
||||||
if job.config.target_id in q.invalidated
|
job = q.queues[arch].pop() or { break }
|
||||||
&& job.created < q.invalidated[job.config.target_id] {
|
|
||||||
// This pop *should* never fail according to the source code
|
|
||||||
q.queues[arch].pop() or { break outer }
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if job.timestamp < time.now() {
|
// TODO idem
|
||||||
job = q.queues[arch].pop() or { break outer }
|
q.reschedule(job, arch) or {}
|
||||||
|
|
||||||
// TODO idem
|
out << job
|
||||||
q.reschedule(job, arch) or {}
|
} else {
|
||||||
|
break
|
||||||
out << job
|
|
||||||
} else {
|
|
||||||
break outer
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue