-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from joshtyf/feature/implement-api-step-executor
Implement API step executor
- Loading branch information
Showing
16 changed files
with
429 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package models | ||
|
||
import ( | ||
"time" | ||
|
||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
) | ||
|
||
type PipelineStepType string | ||
|
||
const ( | ||
APIStep PipelineStepType = "API" | ||
) | ||
|
||
type PipelineStepModel struct { | ||
StepName string `bson:"step_name" json:"step_name"` | ||
StepType PipelineStepType `bson:"step_type" json:"step_type"` | ||
NextStepName string `bson:"next_step_name" json:"next_step_name"` | ||
PrevStepName string `bson:"prev_step_name" json:"prev_step_name"` | ||
Parameters map[string]string `bson:"parameters" json:"parameters"` | ||
IsTerminalStep bool `bson:"is_terminal_step" json:"is_terminal_step"` | ||
} | ||
|
||
type PipelineModel struct { | ||
Id primitive.ObjectID `bson:"_id,omitempty" json:"uuid,omitempty"` // unique id for the pipeline | ||
PipelineName string `bson:"pipeline_name" json:"pipeline_name"` | ||
Version int `bson:"version" json:"version"` | ||
PrevVersionId primitive.ObjectID `bson:"prev_version_id" json:"prev_version_id"` | ||
FirstStepName string `bson:"first_step_name" json:"first_step_name"` | ||
Steps []PipelineStepModel `bson:"steps" json:"steps"` | ||
CreatedOn time.Time `bson:"created_on" json:"created_on"` | ||
} | ||
|
||
func (p *PipelineModel) GetPipelineStep(name string) *PipelineStepModel { | ||
for _, step := range p.Steps { | ||
if step.StepName == name { | ||
return &step | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package models | ||
|
||
import "testing" | ||
|
||
func TestGetPipelineStep(t *testing.T) { | ||
pipeline := PipelineModel{ | ||
Steps: []PipelineStepModel{{StepName: "step1"}, {StepName: "step2"}}, | ||
} | ||
t.Run("Get step 1", func(t *testing.T) { | ||
step := pipeline.GetPipelineStep("step1") | ||
if step == nil { | ||
t.Errorf("Expected step1, got nil") | ||
return | ||
} | ||
if step.StepName != "step1" { | ||
t.Errorf("Expected step1, got %s", step.StepName) | ||
} | ||
}) | ||
t.Run("Expect nil result", func(t *testing.T) { | ||
step := pipeline.GetPipelineStep("step3") | ||
if step != nil { | ||
t.Errorf("Expected nil result, got %v", step) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/joshtyf/flowforge/src/database/models" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
type Pipeline struct { | ||
c *mongo.Client | ||
} | ||
|
||
func NewPipeline(c *mongo.Client) *Pipeline { | ||
return &Pipeline{c: c} | ||
} | ||
|
||
func (p *Pipeline) Create(pm *models.PipelineModel) (*mongo.InsertOneResult, error) { | ||
pm.CreatedOn = time.Now() | ||
res, err := p.c.Database(DatabaseName).Collection("pipelines").InsertOne(context.Background(), pm) | ||
return res, err | ||
} | ||
|
||
func (p *Pipeline) GetById(id string) (*models.PipelineModel, error) { | ||
objId, err := primitive.ObjectIDFromHex(id) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res := p.c.Database(DatabaseName).Collection("pipelines").FindOne(context.Background(), bson.M{"_id": objId}) | ||
if res.Err() != nil { | ||
return nil, res.Err() | ||
} | ||
pipeline := &models.PipelineModel{} | ||
res.Decode(pipeline) | ||
return pipeline, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package events | ||
|
||
import ( | ||
"github.com/gookit/event" | ||
"github.com/joshtyf/flowforge/src/database/models" | ||
) | ||
|
||
const ( | ||
NewServiceRequestEventName = "NewServiceRequestEvent" | ||
) | ||
|
||
type NewServiceRequestEvent struct { | ||
event.BasicEvent | ||
serviceRequest *models.ServiceRequestModel | ||
} | ||
|
||
func NewNewServiceRequestEvent(serviceRequest *models.ServiceRequestModel) *NewServiceRequestEvent { | ||
e := &NewServiceRequestEvent{ | ||
serviceRequest: serviceRequest, | ||
} | ||
e.SetName(NewServiceRequestEventName) | ||
return e | ||
} | ||
|
||
func (e *NewServiceRequestEvent) ServiceRequest() *models.ServiceRequestModel { | ||
return e.serviceRequest | ||
} |
Oops, something went wrong.