mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 20:35:24 +01:00
fix(templates): fill last task for boltdb
This commit is contained in:
parent
f63557d472
commit
6bfe7517f8
@ -362,11 +362,9 @@ func apply(
|
||||
return
|
||||
}
|
||||
|
||||
if filter != nil {
|
||||
if !filter(obj) {
|
||||
if filter != nil && !filter(obj) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
err = applier(obj)
|
||||
if err != nil {
|
||||
@ -405,7 +403,6 @@ func (d *BoltDb) count(bucketID int, props db.ObjectProps, params db.RetrieveQue
|
||||
|
||||
func unmarshalObjects(rawData enumerable, props db.ObjectProps, params db.RetrieveQueryParams, filter func(interface{}) bool, objects interface{}) (err error) {
|
||||
objectsValue := reflect.ValueOf(objects).Elem()
|
||||
//objType := objectsValue.Type().Elem()
|
||||
|
||||
objectsValue.Set(reflect.MakeSlice(objectsValue.Type(), 0, 0))
|
||||
|
||||
@ -450,6 +447,20 @@ func (d *BoltDb) getObjects(bucketID int, props db.ObjectProps, params db.Retrie
|
||||
})
|
||||
}
|
||||
|
||||
func (d *BoltDb) apply(bucketID int, props db.ObjectProps, params db.RetrieveQueryParams, applier func(interface{}) error) error {
|
||||
return d.db.View(func(tx *bbolt.Tx) error {
|
||||
b := tx.Bucket(makeBucketId(props, bucketID))
|
||||
var c enumerable
|
||||
if b == nil {
|
||||
c = emptyEnumerable{}
|
||||
} else {
|
||||
c = b.Cursor()
|
||||
}
|
||||
|
||||
return apply(c, props, params, nil, applier)
|
||||
})
|
||||
}
|
||||
|
||||
func (d *BoltDb) deleteObject(bucketID int, props db.ObjectProps, objectID objectID, tx *bbolt.Tx) error {
|
||||
for _, u := range []db.ObjectProps{db.TemplateProps, db.EnvironmentProps, db.InventoryProps, db.RepositoryProps} {
|
||||
inUse, err := d.isObjectInUse(bucketID, props, objectID, u)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package bolt
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
@ -55,13 +56,44 @@ func (d *BoltDb) GetTemplates(projectID int, filter db.TemplateFilter, params db
|
||||
return
|
||||
}
|
||||
|
||||
var tasks []db.Task
|
||||
templatesMap := make(map[int]*db.Template)
|
||||
|
||||
err = d.getObjects(projectID, db.TaskProps, db.RetrieveQueryParams{}, func(i interface{}) bool {
|
||||
return true
|
||||
}, &tasks)
|
||||
for i := 0; i < len(templates); i++ {
|
||||
templatesMap[templates[i].ID] = &templates[i]
|
||||
}
|
||||
|
||||
//err = db.FillTemplates(d, templates)
|
||||
unfilledTemplateCount := len(templates)
|
||||
|
||||
var errEndOfTemplates = errors.New("no more templates to filling")
|
||||
|
||||
err = d.apply(projectID, db.TaskProps, db.RetrieveQueryParams{}, func(i interface{}) error {
|
||||
task := i.(db.Task)
|
||||
|
||||
tpl, ok := templatesMap[task.TemplateID]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
if tpl.LastTask != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
tpl.LastTask = &db.TaskWithTpl{
|
||||
Task: task,
|
||||
}
|
||||
|
||||
unfilledTemplateCount--
|
||||
|
||||
if unfilledTemplateCount <= 0 {
|
||||
return errEndOfTemplates
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if errors.Is(err, errEndOfTemplates) {
|
||||
err = nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user