Преглед изворни кода

refactor: rename aws_lambda to serverless

Yeuoly пре 5 месеци
родитељ
комит
6a54d44142

+ 1 - 1
docker/serverless.dockerfile

@@ -25,7 +25,7 @@ COPY --from=builder /app/main /app/main
 WORKDIR /app
 
 # check build args
-ARG PLATFORM=aws_lambda
+ARG PLATFORM=serverless
 
 ENV PLATFORM=$PLATFORM
 ENV GIN_MODE=release

+ 1 - 1
internal/core/plugin_daemon/generic.go

@@ -41,7 +41,7 @@ func GenericInvokePlugin[Req any, Rsp any](
 			}
 		case plugin_entities.SESSION_MESSAGE_TYPE_INVOKE:
 			// check if the request contains a aws_event_id
-			if runtime.Type() == plugin_entities.PLUGIN_RUNTIME_TYPE_AWS {
+			if runtime.Type() == plugin_entities.PLUGIN_RUNTIME_TYPE_SERVERLESS {
 				response.WriteError(errors.New(parser.MarshalJson(map[string]string{
 					"error_type": "aws_event_not_supported",
 					"message":    "aws event is not supported by full duplex",

+ 2 - 2
internal/core/plugin_manager/install_to_serverless.go

@@ -70,13 +70,13 @@ func (p *PluginManager) InstallToAWSFromPkg(
 				// check if the plugin is already installed
 				_, err := db.GetOne[models.ServerlessRuntime](
 					db.Equal("checksum", checksum),
-					db.Equal("type", string(models.SERVERLESS_RUNTIME_TYPE_AWS_LAMBDA)),
+					db.Equal("type", string(models.SERVERLESS_RUNTIME_TYPE_SERVERLESS)),
 				)
 				if err == db.ErrDatabaseNotFound {
 					// create a new serverless runtime
 					serverlessModel := &models.ServerlessRuntime{
 						Checksum:               checksum,
-						Type:                   models.SERVERLESS_RUNTIME_TYPE_AWS_LAMBDA,
+						Type:                   models.SERVERLESS_RUNTIME_TYPE_SERVERLESS,
 						FunctionURL:            functionUrl,
 						FunctionName:           functionName,
 						PluginUniqueIdentifier: uniqueIdentity.String(),

+ 2 - 2
internal/core/plugin_manager/manager.go

@@ -72,7 +72,7 @@ type PluginManager struct {
 	// max launching lock to prevent too many plugins launching at the same time
 	maxLaunchingLock chan bool
 
-	// platform, local or aws_lambda
+	// platform, local or serverless
 	platform app.PlatformType
 }
 
@@ -165,7 +165,7 @@ func (p *PluginManager) Launch(configuration *app.Config) {
 	}
 
 	// launch serverless connector
-	if configuration.Platform == app.PLATFORM_AWS_LAMBDA {
+	if configuration.Platform == app.PLATFORM_SERVERLESS {
 		serverless.Init(configuration)
 	}
 

+ 1 - 1
internal/core/plugin_manager/serverless_runtime/run.go

@@ -11,5 +11,5 @@ func (r *AWSPluginRuntime) Wait() (<-chan bool, error) {
 }
 
 func (r *AWSPluginRuntime) Type() plugin_entities.PluginRuntimeType {
-	return plugin_entities.PLUGIN_RUNTIME_TYPE_AWS
+	return plugin_entities.PLUGIN_RUNTIME_TYPE_SERVERLESS
 }

+ 2 - 2
internal/server/http_server.go

@@ -115,9 +115,9 @@ func (app *App) endpointGroup(group *gin.RouterGroup, config *app.Config) {
 }
 
 func (appRef *App) awsLambdaTransactionGroup(group *gin.RouterGroup, config *app.Config) {
-	if config.Platform == app.PLATFORM_AWS_LAMBDA {
+	if config.Platform == app.PLATFORM_SERVERLESS {
 		appRef.awsTransactionHandler = transaction.NewAWSTransactionHandler(
-			time.Duration(config.MaxAWSLambdaTransactionTimeout) * time.Second,
+			time.Duration(config.MaxServerlessTransactionTimeout) * time.Second,
 		)
 		group.POST(
 			"/transaction",

+ 5 - 5
internal/service/install_plugin.go

@@ -44,8 +44,8 @@ func InstallPluginRuntimeToTenant(
 	pluginsWaitForInstallation := []plugin_entities.PluginUniqueIdentifier{}
 
 	runtimeType := plugin_entities.PluginRuntimeType("")
-	if config.Platform == app.PLATFORM_AWS_LAMBDA {
-		runtimeType = plugin_entities.PLUGIN_RUNTIME_TYPE_AWS
+	if config.Platform == app.PLATFORM_SERVERLESS {
+		runtimeType = plugin_entities.PLUGIN_RUNTIME_TYPE_SERVERLESS
 	} else if config.Platform == app.PLATFORM_LOCAL {
 		runtimeType = plugin_entities.PLUGIN_RUNTIME_TYPE_LOCAL
 	} else {
@@ -192,7 +192,7 @@ func InstallPluginRuntimeToTenant(
 			})
 
 			var stream *stream.Stream[plugin_manager.PluginInstallResponse]
-			if config.Platform == app.PLATFORM_AWS_LAMBDA {
+			if config.Platform == app.PLATFORM_SERVERLESS {
 				var zipDecoder *decoder.ZipPluginDecoder
 				var pkgFile []byte
 
@@ -308,8 +308,8 @@ func InstallPluginFromIdentifiers(
 			runtimeType := plugin_entities.PluginRuntimeType("")
 
 			switch config.Platform {
-			case app.PLATFORM_AWS_LAMBDA:
-				runtimeType = plugin_entities.PLUGIN_RUNTIME_TYPE_AWS
+			case app.PLATFORM_SERVERLESS:
+				runtimeType = plugin_entities.PLUGIN_RUNTIME_TYPE_SERVERLESS
 			case app.PLATFORM_LOCAL:
 				runtimeType = plugin_entities.PLUGIN_RUNTIME_TYPE_LOCAL
 			default:

+ 7 - 7
internal/types/app/config.go

@@ -78,9 +78,9 @@ type Config struct {
 	DifyPluginServerlessConnectorURL    *string `envconfig:"DIFY_PLUGIN_SERVERLESS_CONNECTOR_URL"`
 	DifyPluginServerlessConnectorAPIKey *string `envconfig:"DIFY_PLUGIN_SERVERLESS_CONNECTOR_API_KEY"`
 
-	MaxPluginPackageSize           int64 `envconfig:"MAX_PLUGIN_PACKAGE_SIZE" validate:"required"`
-	MaxBundlePackageSize           int64 `envconfig:"MAX_BUNDLE_PACKAGE_SIZE" validate:"required"`
-	MaxAWSLambdaTransactionTimeout int   `envconfig:"MAX_AWS_LAMBDA_TRANSACTION_TIMEOUT"`
+	MaxPluginPackageSize            int64 `envconfig:"MAX_PLUGIN_PACKAGE_SIZE" validate:"required"`
+	MaxBundlePackageSize            int64 `envconfig:"MAX_BUNDLE_PACKAGE_SIZE" validate:"required"`
+	MaxServerlessTransactionTimeout int   `envconfig:"MAX_SERVERLESS_TRANSACTION_TIMEOUT"`
 
 	PythonInterpreterPath string `envconfig:"PYTHON_INTERPRETER_PATH"`
 	PythonEnvInitTimeout  int    `envconfig:"PYTHON_ENV_INIT_TIMEOUT" validate:"required"`
@@ -124,7 +124,7 @@ func (c *Config) Validate() error {
 		}
 	}
 
-	if c.Platform == PLATFORM_AWS_LAMBDA {
+	if c.Platform == PLATFORM_SERVERLESS {
 		if c.DifyPluginServerlessConnectorURL == nil {
 			return fmt.Errorf("dify plugin serverless connector url is empty")
 		}
@@ -133,8 +133,8 @@ func (c *Config) Validate() error {
 			return fmt.Errorf("dify plugin serverless connector api key is empty")
 		}
 
-		if c.MaxAWSLambdaTransactionTimeout == 0 {
-			return fmt.Errorf("max aws lambda transaction timeout is empty")
+		if c.MaxServerlessTransactionTimeout == 0 {
+			return fmt.Errorf("max serverless transaction timeout is empty")
 		}
 	} else if c.Platform == PLATFORM_LOCAL {
 		if c.PluginWorkingPath == "" {
@@ -165,5 +165,5 @@ type PlatformType string
 
 const (
 	PLATFORM_LOCAL      PlatformType = "local"
-	PLATFORM_AWS_LAMBDA PlatformType = "aws_lambda"
+	PLATFORM_SERVERLESS PlatformType = "serverless"
 )

+ 1 - 1
internal/types/app/default.go

@@ -13,7 +13,7 @@ func (config *Config) SetDefault() {
 	setDefaultInt(&config.PluginRemoteInstallingMaxConn, 256)
 	setDefaultInt(&config.MaxPluginPackageSize, 52428800)
 	setDefaultInt(&config.MaxBundlePackageSize, 52428800*12)
-	setDefaultInt(&config.MaxAWSLambdaTransactionTimeout, 150)
+	setDefaultInt(&config.MaxServerlessTransactionTimeout, 300)
 	setDefaultInt(&config.PluginMaxExecutionTimeout, 240)
 	setDefaultString(&config.PluginStorageType, "local")
 	setDefaultInt(&config.PluginMediaCacheSize, 1024)

+ 1 - 1
internal/types/models/plugin.go

@@ -20,7 +20,7 @@ type Plugin struct {
 type ServerlessRuntimeType string
 
 const (
-	SERVERLESS_RUNTIME_TYPE_AWS_LAMBDA ServerlessRuntimeType = "aws_lambda"
+	SERVERLESS_RUNTIME_TYPE_SERVERLESS ServerlessRuntimeType = "serverless"
 )
 
 type ServerlessRuntime struct {

+ 0 - 6
pkg/entities/constants/arch.go

@@ -12,17 +12,11 @@ const (
 	ARM64 Arch = "arm64"
 )
 
-func isAWSLambdaSupportedArch(fl validator.FieldLevel) bool {
-	value := fl.Field().String()
-	return value == string(AMD64)
-}
-
 func isAvailableArch(fl validator.FieldLevel) bool {
 	value := fl.Field().String()
 	return value == string(AMD64) || value == string(ARM64)
 }
 
 func init() {
-	validators.GlobalEntitiesValidator.RegisterValidation("is_aws_lambda_supported_arch", isAWSLambdaSupportedArch)
 	validators.GlobalEntitiesValidator.RegisterValidation("is_available_arch", isAvailableArch)
 }

+ 3 - 3
pkg/entities/plugin_entities/runtime.go

@@ -204,9 +204,9 @@ func (s *PluginRuntime) Error(log string) {
 type PluginRuntimeType string
 
 const (
-	PLUGIN_RUNTIME_TYPE_LOCAL  PluginRuntimeType = "local"
-	PLUGIN_RUNTIME_TYPE_REMOTE PluginRuntimeType = "remote"
-	PLUGIN_RUNTIME_TYPE_AWS    PluginRuntimeType = "aws"
+	PLUGIN_RUNTIME_TYPE_LOCAL      PluginRuntimeType = "local"
+	PLUGIN_RUNTIME_TYPE_REMOTE     PluginRuntimeType = "remote"
+	PLUGIN_RUNTIME_TYPE_SERVERLESS PluginRuntimeType = "serverless"
 )
 
 type PluginRuntimeState struct {