Last active
February 10, 2018 21:42
-
-
Save nictuku/a6dbb463e7426bc21a6b594bfcb2b745 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func newRunner(creds) { | |
&ciRunner{ | |
githubClient: newGithubClient(creds), | |
githubCredentials: creds, | |
// Note: buffered channel. Means that writes to `builds` will almost always return immediately, | |
// unless we accumulate 100 builds in the queue. We don't have a good failure mode if that happens. | |
// That's OK for now. | |
builds: make(chan *event, 100), | |
} | |
} | |
func main() { | |
runner := newRunner() | |
// background goroutine for doing one build at a time. | |
go runner.startBuilder() | |
for event := range server.Events { | |
// this returns almost immediately | |
runner.handleEvent(event) | |
} | |
} | |
func (r *runner) startBuilder() { | |
// Only one thing happening at a time here. | |
for event := range r.builds { | |
runBazelCommand(event) | |
// etc. | |
setCIStatusSuccess() | |
} | |
} | |
func (r *runner) handleEvent(event) { | |
setCIStatusPending() | |
builds<-event | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment