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

Migrated Workflows From In Memory to Db #33

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

keremeyuboglu
Copy link
Collaborator

  • There was a constant error with no table found error. See issue: bugs when use attach database mattn/go-sqlite3#511
    Had to make a change for dev environment since appearently in memory sqlite creates a new in memory db instance when creating a new connection. I haven't run into issues testing the web app and running the integrations tests but I think it's important to keep that in mind.

  • Right now I'm polling the enabled workflows from database in 100ms intervals.

  • Changing defer in GcSessions sped up the integration test by a second since it closed connection earlier(was getting errors in session, so had to tinker with it a lot.)

Some Additional Footnotes

  • I had to relocate some non-db related workflow stuff to persistence/workflow.go. But I'd like them to be under services package but the only way is to create another struct that embeds the db model. Since I haven't seen something like that in the project I've left that as is. Although I've relocated background job related stuff to workflow.go, so that workflowService only have functions that serve the API.

For example in services/workflow.go:

type MyWorkflow struct {
	persistence.Workflow
}

func (workflow MyWorkflow) Call(params ...interface{}) (result interface{}, err error) {
	f := reflect.ValueOf(persistence.FUNC_MAP[workflow.FunctionName])
	if len(params) != f.Type().NumIn() {
		err = errors.New("the number of params is out of index")
		return
	}
	in := make([]reflect.Value, len(params))
	for k, param := range params {
		in[k] = reflect.ValueOf(param)
	}
	res := f.Call(in)
	result = res[0].Interface()
	return
}

Haven't made changes about this yet but when for example creating a workflow, we're returning a generic internal server error if there's no topic in database with that particular name. Shouldn't we specify messages a little bit, but to at what extend. Should I create an error saying that in service layer and catch and serve that error to the user or
Log that error but give a generic error message that it can't be created with bad request instead of server error?

@keremeyuboglu keremeyuboglu linked an issue Aug 4, 2024 that may be closed by this pull request
@bdkiran
Copy link
Contributor

bdkiran commented Aug 5, 2024

Hi Kareem, I'm reviewing your changes and the question about where some of the methods should live.

persistence/session.go Show resolved Hide resolved
persistence/session.go Show resolved Hide resolved
persistence/workflow.go Show resolved Hide resolved
return workflows, err
}

defer rows.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to how we did in sessions and stickyConnections let's explicitly close tho rows instead of leaving it up to defer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm changing all row-related defer statements while I'm at it

@keremeyuboglu keremeyuboglu marked this pull request as ready for review August 5, 2024 17:14
Copy link
Contributor

@bdkiran bdkiran left a comment

Choose a reason for hiding this comment

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

Everything looks good to me here

@bdkiran bdkiran merged commit b3ecea8 into master Aug 6, 2024
@keremeyuboglu keremeyuboglu deleted the 27-migrate-workflows-to-the-database branch August 6, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate Workflows to the Database
2 participants