Skip to content

Commit eb0bf0f

Browse files
committed
remove deleted pipelines from global active pipeline list
1 parent 59bb2bf commit eb0bf0f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

pipeline/pipeline.go

+25
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func (ap *ActivePipelines) Append(p gaia.Pipeline) {
8787
ap.Pipelines = append(ap.Pipelines, p)
8888
}
8989

90+
// Remove removes a pipeline at the given index from ActivePipelines.
91+
func (ap *ActivePipelines) Remove(index int) {
92+
ap.Lock()
93+
defer ap.Unlock()
94+
95+
ap.Pipelines = append(ap.Pipelines[:index], ap.Pipelines[index+1:]...)
96+
}
97+
9098
// GetByName looks up the pipeline by the given name.
9199
func (ap *ActivePipelines) GetByName(n string) *gaia.Pipeline {
92100
var foundPipeline gaia.Pipeline
@@ -157,6 +165,23 @@ func (ap *ActivePipelines) Contains(n string) bool {
157165
return foundPipeline
158166
}
159167

168+
// RemoveDeletedPipelines removes the pipelines whose names are NOT
169+
// present in `existingPipelineNames` from the given ActivePipelines instance.
170+
func (ap *ActivePipelines) RemoveDeletedPipelines(existingPipelineNames []string) {
171+
for i, pipeline := range ap.Pipelines {
172+
found := false
173+
for _, name := range existingPipelineNames {
174+
if pipeline.Name == name {
175+
found = true
176+
break
177+
}
178+
}
179+
if !found {
180+
ap.Remove(i)
181+
}
182+
}
183+
}
184+
160185
// appendTypeToName appends the type to the output binary name.
161186
// This allows us later to define the pipeline type by the name.
162187
func appendTypeToName(n string, pType gaia.PipelineType) string {

pipeline/ticker.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func InitTicker(store *store.Store, scheduler *scheduler.Scheduler) {
5858
// Every file will be handled as an active pipeline and therefore
5959
// saved in the global active pipelines slice.
6060
func checkActivePipelines() {
61+
var existingPipelineNames []string
6162
files, err := ioutil.ReadDir(gaia.Cfg.PipelinePath)
6263
if err != nil {
6364
gaia.Cfg.Logger.Error("cannot read pipelines folder", "error", err.Error(), "path", gaia.Cfg.PipelinePath)
@@ -78,6 +79,8 @@ func checkActivePipelines() {
7879
// Get real pipeline name and check if the global active pipelines slice
7980
// already contains it.
8081
pName := getRealPipelineName(n, pType)
82+
// Add the real pipeline name to the slice of existing pipeline names.
83+
existingPipelineNames = append(existingPipelineNames, pName)
8184
if GlobalActivePipelines.Contains(pName) {
8285
// If SHA256Sum is set, we should check if pipeline has been changed.
8386
p := GlobalActivePipelines.GetByName(pName)
@@ -113,7 +116,7 @@ func checkActivePipelines() {
113116
continue
114117
}
115118

116-
// We couldn't finde the pipeline. Create a new one.
119+
// We couldn't find the pipeline. Create a new one.
117120
var shouldStore = false
118121
if pipeline == nil {
119122
// Create pipeline object and fill it with information
@@ -152,6 +155,7 @@ func checkActivePipelines() {
152155
GlobalActivePipelines.Append(*pipeline)
153156
}
154157
}
158+
GlobalActivePipelines.RemoveDeletedPipelines(existingPipelineNames)
155159
}
156160

157161
// getPipelineType looks up for specific suffix on the given file name.

0 commit comments

Comments
 (0)