-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
133 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package plugin_manager | ||
|
||
import ( | ||
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_manager/installer" | ||
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/decoder" | ||
"github.com/langgenius/dify-plugin-daemon/internal/utils/stream" | ||
) | ||
|
||
func (p *PluginManager) Install(decoder decoder.PluginDecoder) (*stream.Stream[installer.PluginInstallResponse], error) { | ||
return p.installer(decoder) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,71 @@ | ||
package serverless | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_manager/aws_manager" | ||
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/checksum" | ||
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/decoder" | ||
"github.com/langgenius/dify-plugin-daemon/internal/utils/cache" | ||
"github.com/langgenius/dify-plugin-daemon/internal/utils/stream" | ||
) | ||
|
||
var ( | ||
AWS_LAUNCH_LOCK_PREFIX = "aws_launch_lock_" | ||
) | ||
|
||
// UploadPlugin uploads the plugin to the AWS Lambda | ||
func UploadPlugin(r *aws_manager.AWSPluginRuntime) error { | ||
r.Log("Starting to initialize environment") | ||
// return the lambda url and name | ||
func UploadPlugin(decoder decoder.PluginDecoder) (*stream.Stream[LaunchAWSLambdaFunctionResponse], error) { | ||
checksum, err := checksum.CalculateChecksum(decoder) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// check if the plugin has already been initialized, at most 300s | ||
if err := cache.Lock(AWS_LAUNCH_LOCK_PREFIX+r.Checksum(), 300*time.Second, 300*time.Second); err != nil { | ||
return err | ||
if err := cache.Lock(AWS_LAUNCH_LOCK_PREFIX+checksum, 300*time.Second, 300*time.Second); err != nil { | ||
return nil, err | ||
} | ||
defer cache.Unlock(AWS_LAUNCH_LOCK_PREFIX + r.Checksum()) | ||
r.Log("Started to initialize environment") | ||
defer cache.Unlock(AWS_LAUNCH_LOCK_PREFIX + checksum) | ||
|
||
identity, err := r.Identity() | ||
manifest, err := decoder.Manifest() | ||
if err != nil { | ||
return err | ||
return nil, err | ||
} | ||
function, err := FetchLambda(identity.String(), r.Checksum()) | ||
|
||
identity := manifest.Identity() | ||
function, err := FetchLambda(identity, checksum) | ||
if err != nil { | ||
if err != ErrNoLambdaFunction { | ||
return err | ||
return nil, err | ||
} | ||
} else { | ||
// found, return directly | ||
r.LambdaURL = function.FunctionURL | ||
r.LambdaName = function.FunctionName | ||
r.Log(fmt.Sprintf("Found existing lambda function: %s", r.LambdaName)) | ||
return nil | ||
response := stream.NewStreamResponse[LaunchAWSLambdaFunctionResponse](2) | ||
response.Write(LaunchAWSLambdaFunctionResponse{ | ||
Event: LambdaUrl, | ||
Message: function.FunctionURL, | ||
}) | ||
response.Write(LaunchAWSLambdaFunctionResponse{ | ||
Event: Lambda, | ||
Message: function.FunctionName, | ||
}) | ||
return response, nil | ||
} | ||
|
||
// create it if not found | ||
r.Log("Creating new lambda function") | ||
|
||
// create lambda function | ||
packager := NewPackager(r, r.Decoder) | ||
packager := NewPackager(decoder) | ||
context, err := packager.Pack() | ||
if err != nil { | ||
return err | ||
return nil, err | ||
} | ||
defer os.Remove(context.Name()) | ||
defer context.Close() | ||
|
||
response, err := LaunchLambda(identity.String(), r.Checksum(), context) | ||
response, err := LaunchLambda(identity, checksum, context) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for response.Next() { | ||
response, err := response.Read() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
switch response.Event { | ||
case Error: | ||
return fmt.Errorf("error: %s", response.Message) | ||
case LambdaUrl: | ||
r.LambdaURL = response.Message | ||
case Lambda: | ||
r.LambdaName = response.Message | ||
case Info: | ||
r.Log(fmt.Sprintf("installing: %s", response.Message)) | ||
} | ||
return nil, err | ||
} | ||
|
||
return nil | ||
return response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.