-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create jobs queue for scheduling new builds
- Loading branch information
Martin Sehnoutka
committed
Sep 24, 2019
1 parent
7df735e
commit 2452bdc
Showing
5 changed files
with
130 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package queue | ||
|
||
// Build is a request waiting for a worker | ||
type Build struct { | ||
Pipeline string `json:"pipeline"` | ||
Manifest string `json:"manifest"` | ||
} | ||
|
||
// Manifest contains additional metadata attached do a pipeline that are necessary for workers | ||
type Manifest struct { | ||
destination string | ||
} | ||
|
||
// Job is an image build already in progress | ||
type Job struct { | ||
UUID string `json:"uuid"` | ||
Build Build `json:"build"` | ||
} | ||
|
||
// JobQueue contains already running jobs waiting for | ||
type JobQueue struct { | ||
incomingBuilds chan Build | ||
queue []Job | ||
} | ||
|
||
// NewJobQueue creates object of type JobQueue | ||
func NewJobQueue(timeout int, builds chan Build) *JobQueue { | ||
return &JobQueue{ | ||
incomingBuilds: builds, | ||
queue: make([]Job, 10), | ||
} | ||
} | ||
|
||
// StartNewJob starts a new job | ||
func (j *JobQueue) StartNewJob(id string, worker string) Job { | ||
newBuild := <-j.incomingBuilds | ||
job := Job{ | ||
UUID: id, | ||
Build: newBuild, | ||
} | ||
return job | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters