2023-02-20 19:11:18 +00:00
|
|
|
package edgejob
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
2023-06-20 20:51:34 +00:00
|
|
|
"github.com/portainer/portainer/api/dataservices"
|
2023-02-20 19:11:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ServiceTx struct {
|
2023-06-22 21:28:07 +00:00
|
|
|
dataservices.BaseDataServiceTx[portainer.EdgeJob, portainer.EdgeJobID]
|
2023-02-20 19:11:18 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 21:28:07 +00:00
|
|
|
// Create creates a new EdgeJob
|
|
|
|
func (service ServiceTx) Create(edgeJob *portainer.EdgeJob) error {
|
|
|
|
return service.CreateWithID(portainer.EdgeJobID(service.GetNextIdentifier()), edgeJob)
|
2023-02-20 19:11:18 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 21:28:07 +00:00
|
|
|
// CreateWithID creates a new EdgeJob
|
|
|
|
func (service ServiceTx) CreateWithID(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error {
|
2023-02-20 19:11:18 +00:00
|
|
|
edgeJob.ID = ID
|
|
|
|
|
2023-06-22 21:28:07 +00:00
|
|
|
return service.Tx.CreateObjectWithId(BucketName, int(edgeJob.ID), edgeJob)
|
2023-02-20 19:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateEdgeJobFunc is a no-op inside a transaction.
|
|
|
|
func (service ServiceTx) UpdateEdgeJobFunc(ID portainer.EdgeJobID, updateFunc func(edgeJob *portainer.EdgeJob)) error {
|
|
|
|
return errors.New("cannot be called inside a transaction")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNextIdentifier returns the next identifier for an environment(endpoint).
|
|
|
|
func (service ServiceTx) GetNextIdentifier() int {
|
2023-06-22 21:28:07 +00:00
|
|
|
return service.Tx.GetNextIdentifier(BucketName)
|
2023-02-20 19:11:18 +00:00
|
|
|
}
|