Booking trace API
This commit is contained in:
parent
f64563c9ff
commit
ddb4f76af7
106
entrypoint.go
106
entrypoint.go
@ -1,6 +1,9 @@
|
||||
package oclib
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
@ -73,6 +76,11 @@ func AddPath(collection LibDataEnum, path string) {
|
||||
}
|
||||
|
||||
func Init(appName string) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in Init : "+fmt.Sprintf("%v", r)))
|
||||
}
|
||||
}()
|
||||
logs.SetAppName(appName)
|
||||
logs.SetLogger(logs.CreateLogger("main", ""))
|
||||
mongo.MONGOService.Init(models.GetModelsNames(), tools.GetConfig())
|
||||
@ -107,43 +115,73 @@ func GetLogger() zerolog.Logger {
|
||||
return logs.GetLogger()
|
||||
}
|
||||
|
||||
func Search(filters *dbs.Filters, word string, collection LibDataEnum, c ...*tools.HTTPCaller) LibDataShallow {
|
||||
func Search(filters *dbs.Filters, word string, collection LibDataEnum, c ...*tools.HTTPCaller) (data LibDataShallow) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in Search : "+fmt.Sprintf("%v", r)))
|
||||
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r)}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
}
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).Search(filters, word)
|
||||
if err != nil {
|
||||
return LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
}
|
||||
return LibDataShallow{Data: d, Code: code}
|
||||
data = LibDataShallow{Data: d, Code: code}
|
||||
return
|
||||
}
|
||||
|
||||
func LoadAll(collection LibDataEnum, c ...*tools.HTTPCaller) LibDataShallow {
|
||||
func LoadAll(collection LibDataEnum, c ...*tools.HTTPCaller) (data LibDataShallow) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in LoadAll : "+fmt.Sprintf("%v", r)))
|
||||
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r)}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
}
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).LoadAll()
|
||||
if err != nil {
|
||||
return LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
}
|
||||
return LibDataShallow{Data: d, Code: code}
|
||||
data = LibDataShallow{Data: d, Code: code}
|
||||
return
|
||||
}
|
||||
|
||||
func LoadOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) LibData {
|
||||
func LoadOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) (data LibData) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in LoadOne : "+fmt.Sprintf("%v", r)))
|
||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in LoadOne : " + fmt.Sprintf("%v", r)}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
}
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).LoadOne(id)
|
||||
if err != nil {
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
}
|
||||
return LibData{Data: d, Code: code}
|
||||
data = LibData{Data: d, Code: code}
|
||||
return
|
||||
}
|
||||
|
||||
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string, c ...*tools.HTTPCaller) LibData {
|
||||
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string, c ...*tools.HTTPCaller) (data LibData) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in UpdateOne : "+fmt.Sprintf("%v", r)))
|
||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in UpdateOne : " + fmt.Sprintf("%v", r)}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
@ -151,24 +189,40 @@ func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string, c
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(caller).UpdateOne(model.Deserialize(set), id)
|
||||
if err != nil {
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
}
|
||||
return LibData{Data: d, Code: code}
|
||||
data = LibData{Data: d, Code: code}
|
||||
return
|
||||
}
|
||||
|
||||
func DeleteOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) LibData {
|
||||
func DeleteOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) (data LibData) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in DeleteOne : "+fmt.Sprintf("%v", r)))
|
||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in DeleteOne : " + fmt.Sprintf("%v", r)}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
}
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).DeleteOne(id)
|
||||
if err != nil {
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
}
|
||||
return LibData{Data: d, Code: code}
|
||||
data = LibData{Data: d, Code: code}
|
||||
return
|
||||
}
|
||||
|
||||
func StoreOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.HTTPCaller) LibData {
|
||||
func StoreOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.HTTPCaller) (data LibData) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in StoreOne : "+fmt.Sprintf("%v", r)))
|
||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in StoreOne : " + fmt.Sprintf("%v", r)}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
@ -176,12 +230,20 @@ func StoreOne(collection LibDataEnum, object map[string]interface{}, c ...*tools
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(caller).StoreOne(model.Deserialize(object))
|
||||
if err != nil {
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
}
|
||||
return LibData{Data: d, Code: code}
|
||||
data = LibData{Data: d, Code: code}
|
||||
return
|
||||
}
|
||||
|
||||
func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.HTTPCaller) LibData {
|
||||
func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.HTTPCaller) (data LibData) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in CopyOne : "+fmt.Sprintf("%v", r)))
|
||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in UpdateOne : " + fmt.Sprintf("%v", r)}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
@ -189,9 +251,11 @@ func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(caller).CopyOne(model.Deserialize(object))
|
||||
if err != nil {
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
}
|
||||
return LibData{Data: d, Code: code}
|
||||
data = LibData{Data: d, Code: code}
|
||||
return
|
||||
}
|
||||
|
||||
// ================ CAST ========================= //
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
type AbstractWorkflow struct {
|
||||
resources.ResourceSet
|
||||
Graph *graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"`
|
||||
ScheduleActive bool `bson:"schedule_active,omitempty" json:"schedule_active,omitempty"`
|
||||
ScheduleActive bool `json:"schedule_active,omitempty" bson:"schedule_active,omitempty"`
|
||||
Schedule *WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
|
||||
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"`
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func (wfa *workflowMongoAccessor) getExecutions(id string, data *Workflow) ([]*w
|
||||
|
||||
func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
wfa.execution(id, &Workflow{
|
||||
AbstractWorkflow: AbstractWorkflow{ScheduleActive: false},
|
||||
AbstractWorkflow: AbstractWorkflow{ScheduleActive: true},
|
||||
}, true)
|
||||
return wfa.GenericDeleteOne(id, wfa)
|
||||
}
|
||||
@ -138,13 +138,16 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
|
||||
}
|
||||
|
||||
func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delete bool) (int, error) {
|
||||
if !realData.ScheduleActive {
|
||||
return 200, nil
|
||||
}
|
||||
var err error
|
||||
nats := tools.NewNATSCaller()
|
||||
res, code, _ := wfa.LoadOne(id)
|
||||
if code != 200 {
|
||||
return 404, errors.New("could not load workflow")
|
||||
}
|
||||
if (realData.Schedule == nil && !realData.ScheduleActive) || (realData.Schedule == nil && realData.ScheduleActive) {
|
||||
if realData.Schedule == nil && realData.ScheduleActive {
|
||||
mongo.MONGOService.DeleteMultiple(map[string]interface{}{
|
||||
"state": 1,
|
||||
"workflow_id": id,
|
||||
|
Loading…
Reference in New Issue
Block a user