forked from distribworks/dkron
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Victor Castell
committed
Mar 30, 2018
1 parent
4071e4c
commit 4f0b3cb
Showing
11 changed files
with
508 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/go-plugin" | ||
dkplugin "github.com/victorcoder/dkron/plugin" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeConfig{ | ||
HandshakeConfig: dkplugin.Handshake, | ||
Plugins: map[string]plugin.Plugin{ | ||
"executor": &dkplugin.ExecutorPlugin{Executor: &Shell{}}, | ||
}, | ||
|
||
// A non-nil value here enables gRPC serving for this plugin... | ||
GRPCServer: plugin.DefaultGRPCServer, | ||
}) | ||
} |
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,19 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/victorcoder/dkron/dkron" | ||
) | ||
|
||
// FilesOutput plugin that saves each execution log | ||
// in it's own file in the file system. | ||
type Shell struct { | ||
Param1 string | ||
Param2 bool | ||
} | ||
|
||
// Process method of the plugin | ||
func (s *Shell) Execute(args *dkron.ExecutorArgs) error { | ||
return errors.New("Foo bar") | ||
} |
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,14 @@ | ||
package dkron | ||
|
||
// KV is the interface that we're exposing as a plugin. | ||
type Executor interface { | ||
Execute(args *ExecutorArgs) error | ||
} | ||
|
||
// Arguments for calling an execution processor | ||
type ExecutorArgs struct { | ||
// The execution to pass to the processor | ||
Execution Execution | ||
// The configuration for this plugin call | ||
Config PluginConfig | ||
} |
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,60 @@ | ||
package plugin | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/grpc" | ||
|
||
"github.com/hashicorp/go-plugin" | ||
"github.com/victorcoder/dkron/dkron" | ||
"github.com/victorcoder/dkron/proto" | ||
) | ||
|
||
// This is the implementation of plugin.Plugin so we can serve/consume this. | ||
// We also implement GRPCPlugin so that this plugin can be served over | ||
// gRPC. | ||
type ExecutorPlugin struct { | ||
plugin.NetRPCUnsupportedPlugin | ||
Executor dkron.Executor | ||
} | ||
|
||
func (p *ExecutorPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { | ||
proto.RegisterExecutorServer(s, ExecutorServer{Impl: p.Executor}) | ||
return nil | ||
} | ||
|
||
func (p *ExecutorPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) { | ||
return &ExecutorClient{client: proto.NewExecutorClient(c)}, nil | ||
} | ||
|
||
// Here is the gRPC client that GRPCClient talks to. | ||
type ExecutorClient struct { | ||
// This is the real implementation | ||
client proto.ExecutorClient | ||
} | ||
|
||
func (m *ExecutorClient) Execute(args *proto.ExecutorArgs) error { | ||
// This is where the magic conversion to Proto happens | ||
a := &proto.ExecutorArgs{ | ||
Execution: &proto.Execution{}, | ||
} | ||
_, err := m.client.Execute(context.Background(), &proto.ExecuteRequest{ | ||
ExecutorArgs: a, | ||
}) | ||
return err | ||
} | ||
|
||
// Here is the gRPC server that GRPCClient talks to. | ||
type ExecutorServer struct { | ||
// This is the real implementation | ||
Impl dkron.Executor | ||
} | ||
|
||
func (m ExecutorServer) Execute(ctx context.Context, req *proto.ExecuteRequest) (*proto.ExecuteResponse, error) { | ||
// This is where the magic conversion to native dkron happens | ||
args := &dkron.ExecutorArgs{ | ||
Execution: dkron.Execution{}, | ||
} | ||
err := m.Impl.Execute(args) | ||
return &proto.ExecuteResponse{err.Error()}, err | ||
} |
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.