Skip to content

Commit 3ed0712

Browse files
committed
[POC] Automatically update pipelines every minute.
1 parent 59bb2bf commit 3ed0712

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

pipeline/git.go

+30
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,33 @@ func gitCloneRepo(repo *gaia.GitRepo) error {
106106

107107
return nil
108108
}
109+
110+
func updateAllCurrentPipelines() {
111+
// Get all active pipelines
112+
for pipeline := range GlobalActivePipelines.Iter() {
113+
r, err := git.PlainOpen(pipeline.Repo.LocalDest)
114+
if err != nil {
115+
// ignore for now
116+
return
117+
}
118+
119+
beforPull, _ := r.Head()
120+
tree, _ := r.Worktree()
121+
tree.Pull(&git.PullOptions{
122+
RemoteName: "origin",
123+
})
124+
afterPull, _ := r.Head()
125+
126+
// if there are no changes...
127+
if beforPull.Hash() == afterPull.Hash() {
128+
continue
129+
}
130+
131+
// otherwise build the pipeline
132+
b := newBuildPipeline(pipeline.Type)
133+
createPipeline := &gaia.CreatePipeline{}
134+
createPipeline.Pipeline = pipeline
135+
b.ExecuteBuild(createPipeline)
136+
}
137+
138+
}

pipeline/ticker.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import (
1818
const (
1919
// tickerIntervalSeconds defines how often the ticker will tick.
2020
// Definition in seconds.
21-
tickerIntervalSeconds = 5
21+
tickerIntervalSeconds = 5
22+
pollTicketIntervalMinutes = 1
2223
)
2324

2425
// storeService is an instance of store.
@@ -52,6 +53,17 @@ func InitTicker(store *store.Store, scheduler *scheduler.Scheduler) {
5253
}
5354
}
5455
}()
56+
57+
pollTicket := time.NewTicker(pollTicketIntervalMinutes * time.Minute)
58+
go func() {
59+
defer pollTicket.Stop()
60+
for {
61+
select {
62+
case <-pollTicket.C:
63+
updateAllCurrentPipelines()
64+
}
65+
}
66+
}()
5567
}
5668

5769
// checkActivePipelines looks up all files in the pipeline folder.

0 commit comments

Comments
 (0)