simple-workflow-go is a lightweight framework designed to simplify workflow management in Go applications. With easy integration and a simple setup, it allows you to focus on orchestrating tasks and managing workflow state effectively without unnecessary complexity.
simple-workflow-go is a lightweight and efficient workflow framework designed for easy integration into applications written in Go. This framework simplifies the orchestration of complex processes, enabling developers to manage workflow states, activities, and tasks seamlessly.
Experience the framework in action with our visual demo showcasing its capabilities and features!

The framework allows you to initialize your backend using a PSQL server. Here’s a quick example of how to set up the PSQL backend:
const (
DbHost = "localhost"
DbPort = 5432
DbName = "postgres"
DbUser = "user"
DbPassword = "123456"
)
func InitPSQLBackend(logger *zap.Logger) (backend.Backend, error) {
hostname, err := os.Hostname()
if err != nil { return nil, err }
db, err := psql.Connect(DbHost, DbPort, DbUser, DbPassword, DbName, nil)
if err != nil { return nil, err }
err = psql.PrepareDB(db) // auto-create table if not exists
if err != nil { return nil, err }
dataConverter := dataconverter.NewJsonDataConverter()
be := psql.NewPSQLBackend(hostname, 5*time.Minute, dataConverter, db, logger)
return be, nil
}
Define activities to carry out specific tasks. Here’s an example of a payment activity:
type PaymentInput struct {
Value int64
}
func PaymentActivity(ctx context.Context, input *PaymentInput) (*Void, error) {
r := rand.Intn(100)
if r < 30 { // 30% chance of failure
return &Void{}, nil
} else {
return nil, errors.New("payment failed")
}
}
Build workflows by orchestrating these activities, handling errors and iterating through cycles:
func SubscriptionWorkflow(ctx context.Context, input *SubscriptionWorkflowInput) (*SubscriptionWorkflowOutput, error) {
// Workflow logic here...
}
Workers are integral to executing activities and workflows. You can create both activity and workflow workers:
aw, err := worker.NewActivityWorkersBuilder().
WithName("demo activity worker").
WithBackend(be).
WithLogger(logger).
RegisterActivities(PaymentActivity).
WithActivityWorkerOpts(activity_worker.WithTaskProcessorMaxBackoffInterval(1 * time.Minute)).
Build()
Launching workflows is straightforward. Use the ScheduleWorkflow method:
err := client.ScheduleWorkflow(ctx, be, SubscriptionWorkflow, &SubscriptionWorkflowInput{
TotalAmount: totalAmount,
Cycles: cycles,
}, client.WorkflowScheduleOptions{
WorkflowID: workflowID,
Version: "1",
})
To debug a workflow, utilize the WorkflowDebugger feature that allows you to inspect runtime variables and the current state:
dbg := debug.NewWorkflowDebugger(be)
vars, err := dbg.QueryUserDefinedVars(SubscriptionWorkflow, workflowID)
Explore various examples under the examples directory to see how to implement and utilize the simple-workflow-go framework effectively.
Start building efficient workflows today with simple-workflow-go!
No comments yet.
Sign in to be the first to comment.