Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement API step executor #38

Merged
merged 19 commits into from
Jan 25, 2024
Merged

Conversation

joshtyf
Copy link
Owner

@joshtyf joshtyf commented Jan 24, 2024

Description

Pipeline Execution

I created a basic pipeline executor. The flow is like this:

  1. New service request created --> triggers NewServiceRequestEvent (see https://github.com/gookit/event)
  2. StepExecutionManager listens for NewServiceRequestEvent and begins working on the request

The logic of executing the request steps is as follows:

  1. Fetch the pipeline from the database. This is needed to know what are the steps to execute
  2. Iteratively visit each step, calling the various executors registered to the StepExecutionManager. Registration is done via the WithExecutor method (see Golang options design pattern). The parameters submitted via the user when creating a new service request is passed in via context.Context. We will use the same method to pass intermediate results between steps in the future

Seeding

I've also added seeding for the pipeline.

Miscellaneous

  • @Zheng-Zhi-Qiang we forgot to add the json embedding previously. Not too sure how you were creating new service requests without this embedding.
  • Added default values when creating new service requests
  • Added fe and be profiles for docker so that it's easier to run backend only without building the frontend.
    • docker compose --profile be -p flowforge up --build --> for running backend only
    • docker compose --profile be-seed -p flowforge up --build --> for seeding the database

Future TODOs:

  • Log each step execution into the SQL database
  • Figure out how to rollback/resume in the event of faults and errors
  • Tidy up logger using options design pattern
  • Create approval step

@joshtyf joshtyf added backend Backend related feature A new feature labels Jan 24, 2024
@joshtyf joshtyf added this to the M1: Basic setup milestone Jan 24, 2024
@joshtyf joshtyf self-assigned this Jan 24, 2024
type PipelineModel struct {
Uuid primitive.ObjectID `bson:"_id,omitempty" json:"uuid,omitempty"` // unique id for the pipeline
PipelineName string `bson:"pipeline_name" json:"pipeline_name"`
PipelineId string `bson:"pipeline_id" json:"pipeline_id"` // id for the pipeline. non-unique and uses `Version` to differentiate between different versions of the pipeline
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this means different versions of the pipeline will have the same ID and different uuid?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Owner Author

@joshtyf joshtyf Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, the admin might create a pipeline called "Create EC2"

the first version will be uuid=1, pipelineId=1, pipelineName=createEC2, version=1

then he updates the pipeline by changing the URL.
so the 2nd version will be uuid=2, pipelineId=1, pipelineName=createEC2, version=2

Updates

I've made the following changes:

  • PipelineUuid --> PipelineId
  • Old PipelineId removed in favour of PrevVersionId

This way, we can still aggregate pipelines that are of the same ancestry together without the naming confusion.

LastUpdated time.Time `bson:"last_updated"`
Remarks string `bson:"remarks"`
Id primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
PipelineUuid string `bson:"pipeline_uuid" json:"pipeline_uuid"` // should we use primitive.ObjectID here?
Copy link
Collaborator

@Ziyang-98 Ziyang-98 Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think string is fine since UUID can have hyphens in it

Copy link
Owner Author

@joshtyf joshtyf Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, it's not really a UUID. According to the documents, the mongo ObjectID is just a '24 character hexadecimal value'.

I'm just calling it UUID cause I don't want to call it pipelineId in the service request model as it will be confused with the actual pipelineId in the pipeline model.

Maybe I'll change this

Updates

see #38 (comment)

Copy link
Collaborator

@Ziyang-98 Ziyang-98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Took note of the models too, thanks. Do make sure that the event listener for NewServiceRequest can handle multiple events asynchronously. Maybe can write some test cases to ensure its working properly.

@joshtyf joshtyf force-pushed the feature/implement-api-step-executor branch from 05d5178 to 491743b Compare January 25, 2024 11:31
replaced PipelineUuid with PipelineId
old PipelineId has been removed in favour of PrevVersionId
@joshtyf joshtyf force-pushed the feature/implement-api-step-executor branch from d724a4c to 9130695 Compare January 25, 2024 11:48
@joshtyf joshtyf merged commit 88cf3ab into main Jan 25, 2024
2 checks passed
@joshtyf joshtyf deleted the feature/implement-api-step-executor branch January 25, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend related feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants