light modification
This commit is contained in:
		@@ -4,7 +4,7 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/dbs"
 | 
						"cloud.o-forge.io/core/oc-lib/dbs"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/common"
 | 
						"cloud.o-forge.io/core/oc-lib/models/common/enum"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/utils"
 | 
						"cloud.o-forge.io/core/oc-lib/models/utils"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/tools"
 | 
						"cloud.o-forge.io/core/oc-lib/tools"
 | 
				
			||||||
	"go.mongodb.org/mongo-driver/bson/primitive"
 | 
						"go.mongodb.org/mongo-driver/bson/primitive"
 | 
				
			||||||
@@ -18,7 +18,7 @@ type Booking struct {
 | 
				
			|||||||
	DestPeerID           string             `json:"dest_peer_id,omitempty"`                             // DestPeerID is the ID of the destination peer
 | 
						DestPeerID           string             `json:"dest_peer_id,omitempty"`                             // DestPeerID is the ID of the destination peer
 | 
				
			||||||
	WorkflowID           string             `json:"workflow_id,omitempty" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
 | 
						WorkflowID           string             `json:"workflow_id,omitempty" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
 | 
				
			||||||
	ExecutionID          string             `json:"execution_id,omitempty" bson:"execution_id,omitempty" validate:"required"`
 | 
						ExecutionID          string             `json:"execution_id,omitempty" bson:"execution_id,omitempty" validate:"required"`
 | 
				
			||||||
	State                common.ScheduledType `json:"state,omitempty" bson:"state,omitempty" validate:"required"`                             // State is the state of the booking
 | 
						State                enum.ScheduledType `json:"state,omitempty" bson:"state,omitempty" validate:"required"`                             // State is the state of the booking
 | 
				
			||||||
	ExpectedStartDate    time.Time          `json:"expected_start_date,omitempty" bson:"expected_start_date,omitempty" validate:"required"` // ExpectedStartDate is the expected start date of the booking
 | 
						ExpectedStartDate    time.Time          `json:"expected_start_date,omitempty" bson:"expected_start_date,omitempty" validate:"required"` // ExpectedStartDate is the expected start date of the booking
 | 
				
			||||||
	ExpectedEndDate      *time.Time         `json:"expected_end_date,omitempty" bson:"expected_end_date,omitempty" validate:"required"`     // ExpectedEndDate is the expected end date of the booking
 | 
						ExpectedEndDate      *time.Time         `json:"expected_end_date,omitempty" bson:"expected_end_date,omitempty" validate:"required"`     // ExpectedEndDate is the expected end date of the booking
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -41,7 +41,7 @@ func (wfa *Booking) Check(id string, start time.Time, end *time.Time, parrallelA
 | 
				
			|||||||
	res, code, err := accessor.Search(&dbs.Filters{
 | 
						res, code, err := accessor.Search(&dbs.Filters{
 | 
				
			||||||
		And: map[string][]dbs.Filter{ // check if there is a booking on the same compute resource by filtering on the compute_resource_id, the state and the execution date
 | 
							And: map[string][]dbs.Filter{ // check if there is a booking on the same compute resource by filtering on the compute_resource_id, the state and the execution date
 | 
				
			||||||
			"resource_id": {{Operator: dbs.EQUAL.String(), Value: id}},
 | 
								"resource_id": {{Operator: dbs.EQUAL.String(), Value: id}},
 | 
				
			||||||
			"state":       {{Operator: dbs.EQUAL.String(), Value: common.DRAFT.EnumIndex()}},
 | 
								"state":       {{Operator: dbs.EQUAL.String(), Value: enum.DRAFT.EnumIndex()}},
 | 
				
			||||||
			"expected_start_date": {
 | 
								"expected_start_date": {
 | 
				
			||||||
				{Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(*end)},
 | 
									{Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(*end)},
 | 
				
			||||||
				{Operator: dbs.GTE.String(), Value: primitive.NewDateTimeFromTime(start)},
 | 
									{Operator: dbs.GTE.String(), Value: primitive.NewDateTimeFromTime(start)},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/dbs"
 | 
						"cloud.o-forge.io/core/oc-lib/dbs"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/logs"
 | 
						"cloud.o-forge.io/core/oc-lib/logs"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/common"
 | 
						"cloud.o-forge.io/core/oc-lib/models/common/enum"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/utils"
 | 
						"cloud.o-forge.io/core/oc-lib/models/utils"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/tools"
 | 
						"cloud.o-forge.io/core/oc-lib/tools"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -47,10 +47,10 @@ func (a *bookingMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int
 | 
				
			|||||||
func (a *bookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
 | 
					func (a *bookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
 | 
				
			||||||
	return utils.GenericLoadOne[*Booking](id, func(d utils.DBObject) (utils.DBObject, int, error) {
 | 
						return utils.GenericLoadOne[*Booking](id, func(d utils.DBObject) (utils.DBObject, int, error) {
 | 
				
			||||||
		if (d.(*Booking).ExpectedEndDate) == nil {
 | 
							if (d.(*Booking).ExpectedEndDate) == nil {
 | 
				
			||||||
			d.(*Booking).State = common.FORGOTTEN
 | 
								d.(*Booking).State = enum.FORGOTTEN
 | 
				
			||||||
			utils.GenericRawUpdateOne(d, id, a)
 | 
								utils.GenericRawUpdateOne(d, id, a)
 | 
				
			||||||
		} else if d.(*Booking).State == common.SCHEDULED && time.Now().UTC().After(*&d.(*Booking).ExpectedStartDate) {
 | 
							} else if d.(*Booking).State == enum.SCHEDULED && time.Now().UTC().After(*&d.(*Booking).ExpectedStartDate) {
 | 
				
			||||||
			d.(*Booking).State = common.DELAYED
 | 
								d.(*Booking).State = enum.DELAYED
 | 
				
			||||||
			utils.GenericRawUpdateOne(d, id, a)
 | 
								utils.GenericRawUpdateOne(d, id, a)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return d, 200, nil
 | 
							return d, 200, nil
 | 
				
			||||||
@@ -67,8 +67,8 @@ func (a *bookingMongoAccessor) Search(filters *dbs.Filters, search string, isDra
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (a *bookingMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
 | 
					func (a *bookingMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
 | 
				
			||||||
	return func(d utils.DBObject) utils.ShallowDBObject {
 | 
						return func(d utils.DBObject) utils.ShallowDBObject {
 | 
				
			||||||
		if d.(*Booking).State == common.SCHEDULED && time.Now().UTC().After(*&d.(*Booking).ExpectedStartDate) {
 | 
							if d.(*Booking).State == enum.SCHEDULED && time.Now().UTC().After(*&d.(*Booking).ExpectedStartDate) {
 | 
				
			||||||
			d.(*Booking).State = common.DELAYED
 | 
								d.(*Booking).State = enum.DELAYED
 | 
				
			||||||
			utils.GenericRawUpdateOne(d, d.GetID(), a)
 | 
								utils.GenericRawUpdateOne(d, d.GetID(), a)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return d
 | 
							return d
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/dbs"
 | 
						"cloud.o-forge.io/core/oc-lib/dbs"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/booking"
 | 
						"cloud.o-forge.io/core/oc-lib/models/booking"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/common"
 | 
						"cloud.o-forge.io/core/oc-lib/models/common/enum"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/common/pricing"
 | 
						"cloud.o-forge.io/core/oc-lib/models/common/pricing"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/utils"
 | 
						"cloud.o-forge.io/core/oc-lib/models/utils"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/tools"
 | 
						"cloud.o-forge.io/core/oc-lib/tools"
 | 
				
			||||||
@@ -23,7 +23,7 @@ type WorkflowExecutions struct {
 | 
				
			|||||||
	utils.AbstractObject                    // AbstractObject contains the basic fields of an object (id, name)
 | 
						utils.AbstractObject                    // AbstractObject contains the basic fields of an object (id, name)
 | 
				
			||||||
	ExecDate             time.Time          `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` // ExecDate is the execution date of the workflow, is required
 | 
						ExecDate             time.Time          `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` // ExecDate is the execution date of the workflow, is required
 | 
				
			||||||
	EndDate              *time.Time         `json:"end_date,omitempty" bson:"end_date,omitempty"`                                 // EndDate is the end date of the workflow
 | 
						EndDate              *time.Time         `json:"end_date,omitempty" bson:"end_date,omitempty"`                                 // EndDate is the end date of the workflow
 | 
				
			||||||
	State                common.ScheduledType `json:"state" bson:"state" default:"0"`                                               // State is the state of the workflow
 | 
						State                enum.ScheduledType `json:"state" bson:"state" default:"0"`                                               // State is the state of the workflow
 | 
				
			||||||
	WorkflowID           string             `json:"workflow_id" bson:"workflow_id,omitempty"`                                     // WorkflowID is the ID of the workflow
 | 
						WorkflowID           string             `json:"workflow_id" bson:"workflow_id,omitempty"`                                     // WorkflowID is the ID of the workflow
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -55,7 +55,7 @@ func (ws *WorkflowExecutions) PurgeDraft(request *tools.APIRequest) error {
 | 
				
			|||||||
	accessor := ws.GetAccessor(request)
 | 
						accessor := ws.GetAccessor(request)
 | 
				
			||||||
	res, code, err := accessor.Search(&dbs.Filters{
 | 
						res, code, err := accessor.Search(&dbs.Filters{
 | 
				
			||||||
		And: map[string][]dbs.Filter{ // check if there is a booking on the same compute resource by filtering on the compute_resource_id, the state and the execution date
 | 
							And: map[string][]dbs.Filter{ // check if there is a booking on the same compute resource by filtering on the compute_resource_id, the state and the execution date
 | 
				
			||||||
			"state":       {{Operator: dbs.EQUAL.String(), Value: common.DRAFT.EnumIndex()}},
 | 
								"state":       {{Operator: dbs.EQUAL.String(), Value: enum.DRAFT.EnumIndex()}},
 | 
				
			||||||
			"workflow_id": {{Operator: dbs.EQUAL.String(), Value: ws.WorkflowID}},
 | 
								"workflow_id": {{Operator: dbs.EQUAL.String(), Value: ws.WorkflowID}},
 | 
				
			||||||
			"execution_date": {
 | 
								"execution_date": {
 | 
				
			||||||
				{Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(*ws.EndDate)},
 | 
									{Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(*ws.EndDate)},
 | 
				
			||||||
@@ -77,13 +77,13 @@ func (wfa *WorkflowExecutions) ArgoStatusToState(status string) *WorkflowExecuti
 | 
				
			|||||||
	status = strings.ToLower(status)
 | 
						status = strings.ToLower(status)
 | 
				
			||||||
	switch status {
 | 
						switch status {
 | 
				
			||||||
	case "succeeded": // Succeeded
 | 
						case "succeeded": // Succeeded
 | 
				
			||||||
		wfa.State = common.SUCCESS
 | 
							wfa.State = enum.SUCCESS
 | 
				
			||||||
	case "pending": // Pending
 | 
						case "pending": // Pending
 | 
				
			||||||
		wfa.State = common.SCHEDULED
 | 
							wfa.State = enum.SCHEDULED
 | 
				
			||||||
	case "running": // Running
 | 
						case "running": // Running
 | 
				
			||||||
		wfa.State = common.STARTED
 | 
							wfa.State = enum.STARTED
 | 
				
			||||||
	default: // Failed
 | 
						default: // Failed
 | 
				
			||||||
		wfa.State = common.FAILURE
 | 
							wfa.State = enum.FAILURE
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return wfa
 | 
						return wfa
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -119,7 +119,7 @@ func (d *WorkflowExecutions) bookEach(wfID string, dt tools.DataType, priceds []
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		end := start.Add(time.Duration(priced.GetExplicitDurationInS()) * time.Second)
 | 
							end := start.Add(time.Duration(priced.GetExplicitDurationInS()) * time.Second)
 | 
				
			||||||
		bookingItem := &booking.Booking{
 | 
							bookingItem := &booking.Booking{
 | 
				
			||||||
			State:             common.DRAFT,
 | 
								State:             enum.DRAFT,
 | 
				
			||||||
			ResourceID:        priced.GetID(),
 | 
								ResourceID:        priced.GetID(),
 | 
				
			||||||
			ResourceType:      dt,
 | 
								ResourceType:      dt,
 | 
				
			||||||
			DestPeerID:        priced.GetCreatorID(),
 | 
								DestPeerID:        priced.GetCreatorID(),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/dbs"
 | 
						"cloud.o-forge.io/core/oc-lib/dbs"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/logs"
 | 
						"cloud.o-forge.io/core/oc-lib/logs"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/common"
 | 
						"cloud.o-forge.io/core/oc-lib/models/common/enum"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/utils"
 | 
						"cloud.o-forge.io/core/oc-lib/models/utils"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/tools"
 | 
						"cloud.o-forge.io/core/oc-lib/tools"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -43,12 +43,12 @@ func (wfa *workflowExecutionMongoAccessor) CopyOne(data utils.DBObject) (utils.D
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (a *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
 | 
					func (a *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
 | 
				
			||||||
	return utils.GenericLoadOne[*WorkflowExecutions](id, func(d utils.DBObject) (utils.DBObject, int, error) {
 | 
						return utils.GenericLoadOne[*WorkflowExecutions](id, func(d utils.DBObject) (utils.DBObject, int, error) {
 | 
				
			||||||
		if d.(*WorkflowExecutions).State == common.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
 | 
							if d.(*WorkflowExecutions).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
 | 
				
			||||||
			utils.GenericDeleteOne(d.GetID(), a)
 | 
								utils.GenericDeleteOne(d.GetID(), a)
 | 
				
			||||||
			return nil, 404, errors.New("Not found")
 | 
								return nil, 404, errors.New("Not found")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if d.(*WorkflowExecutions).State == common.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
 | 
							if d.(*WorkflowExecutions).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
 | 
				
			||||||
			d.(*WorkflowExecutions).State = common.FORGOTTEN
 | 
								d.(*WorkflowExecutions).State = enum.FORGOTTEN
 | 
				
			||||||
			utils.GenericRawUpdateOne(d, id, a)
 | 
								utils.GenericRawUpdateOne(d, id, a)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return d, 200, nil
 | 
							return d, 200, nil
 | 
				
			||||||
@@ -65,12 +65,12 @@ func (a *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search str
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (a *workflowExecutionMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
 | 
					func (a *workflowExecutionMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
 | 
				
			||||||
	return func(d utils.DBObject) utils.ShallowDBObject {
 | 
						return func(d utils.DBObject) utils.ShallowDBObject {
 | 
				
			||||||
		if d.(*WorkflowExecutions).State == common.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
 | 
							if d.(*WorkflowExecutions).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
 | 
				
			||||||
			utils.GenericDeleteOne(d.GetID(), a)
 | 
								utils.GenericDeleteOne(d.GetID(), a)
 | 
				
			||||||
			return nil
 | 
								return nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if d.(*WorkflowExecutions).State == common.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
 | 
							if d.(*WorkflowExecutions).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
 | 
				
			||||||
			d.(*WorkflowExecutions).State = common.FORGOTTEN
 | 
								d.(*WorkflowExecutions).State = enum.FORGOTTEN
 | 
				
			||||||
			utils.GenericRawUpdateOne(d, d.GetID(), a)
 | 
								utils.GenericRawUpdateOne(d, d.GetID(), a)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return d
 | 
							return d
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,7 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/common"
 | 
						"cloud.o-forge.io/core/oc-lib/models/common/enum"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/peer"
 | 
						"cloud.o-forge.io/core/oc-lib/models/peer"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/utils"
 | 
						"cloud.o-forge.io/core/oc-lib/models/utils"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/workflow"
 | 
						"cloud.o-forge.io/core/oc-lib/models/workflow"
 | 
				
			||||||
@@ -140,7 +140,7 @@ func (ws *WorkflowSchedule) getExecutions(workflow *workflow.Workflow) ([]*Workf
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
			ExecDate:   date.Start,       // set the execution date
 | 
								ExecDate:   date.Start,       // set the execution date
 | 
				
			||||||
			EndDate:    date.End,         // set the end date
 | 
								EndDate:    date.End,         // set the end date
 | 
				
			||||||
			State:      common.DRAFT,     // set the state to 1 (scheduled)
 | 
								State:      enum.DRAFT,       // set the state to 1 (scheduled)
 | 
				
			||||||
			WorkflowID: workflow.GetID(), // set the workflow id dependancy of the execution
 | 
								WorkflowID: workflow.GetID(), // set the workflow id dependancy of the execution
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		workflows_executions = append(workflows_executions, obj)
 | 
							workflows_executions = append(workflows_executions, obj)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user