Skip to content

Commit

Permalink
feat: add context in module interface (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkYuan authored Mar 11, 2024
1 parent d845aa1 commit 729b89b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/modules/generators/app_configurations_generator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package generators

import (
"context"
"errors"
"fmt"

Expand Down Expand Up @@ -164,7 +165,7 @@ func (g *appConfigurationGenerator) callModules(projectModuleConfigs map[string]

// invoke the plugin
log.Infof("invoke module:%s with request:%s", t, protoRequest.String())
response, err := plugin.Module.Generate(protoRequest)
response, err := plugin.Module.Generate(context.Background(), protoRequest)
if err != nil {
return nil, fmt.Errorf("invoke kusion module: %s failed. %w", t, err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/modules/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Generator interface {

// Module is the interface that we're exposing as a kusion module plugin.
type Module interface {
Generate(req *proto.GeneratorRequest) (*proto.GeneratorResponse, error)
Generate(ctx context.Context, req *proto.GeneratorRequest) (*proto.GeneratorResponse, error)
}

// NewGeneratorFunc is a function that returns a Generator.
Expand All @@ -32,8 +32,8 @@ type GRPCClient struct {
client proto.ModuleClient
}

func (c *GRPCClient) Generate(req *proto.GeneratorRequest) (*proto.GeneratorResponse, error) {
return c.client.Generate(context.Background(), req)
func (c *GRPCClient) Generate(ctx context.Context, req *proto.GeneratorRequest) (*proto.GeneratorResponse, error) {
return c.client.Generate(ctx, req)
}

type GRPCServer struct {
Expand All @@ -49,7 +49,7 @@ func (s *GRPCServer) Generate(ctx context.Context, req *proto.GeneratorRequest)
res = &proto.GeneratorResponse{}
}
}()
res, err = s.Impl.Generate(req)
res, err = s.Impl.Generate(ctx, req)
return
}

Expand Down

0 comments on commit 729b89b

Please sign in to comment.