Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATP v3 refactor #57

Merged
merged 10 commits into from
Oct 20, 2023
450 changes: 336 additions & 114 deletions atp/client.go

Large diffs are not rendered by default.

35 changes: 25 additions & 10 deletions atp/protocol.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,70 @@
package atp

import (
"fmt"
"github.com/fxamacker/cbor/v2"
"go.flow.arcalot.io/pluginsdk/schema"
)

const ProtocolVersion int64 = 2
const ProtocolVersion int64 = 3

type HelloMessage struct {
Version int64 `cbor:"version"`
Schema any `cbor:"schema"`
}

type StartWorkMessage struct {
type WorkStartMessage struct {
StepID string `cbor:"id"`
Config any `cbor:"config"`
}

// All messages that can be contained in a RuntimeMessage struct.
const (
MessageTypeWorkDone uint32 = 1
MessageTypeSignal uint32 = 2
MessageTypeClientDone uint32 = 3
MessageTypeWorkStart uint32 = 1
MessageTypeWorkDone uint32 = 2
MessageTypeSignal uint32 = 3
MessageTypeClientDone uint32 = 4
MessageTypeError uint32 = 5
)

type RuntimeMessage struct {
MessageID uint32 `cbor:"id"`
RunID string `cbor:"run_id"`
MessageData any `cbor:"data"`
}

type DecodedRuntimeMessage struct {
MessageID uint32 `cbor:"id"`
RunID string `cbor:"run_id"`
RawMessageData cbor.RawMessage `cbor:"data"`
}

type workDoneMessage struct {
type WorkDoneMessage struct {
StepID string `cbor:"step_id"`
OutputID string `cbor:"output_id"`
OutputData any `cbor:"output_data"`
DebugLogs string `cbor:"debug_logs"`
}

type signalMessage struct {
StepID string `cbor:"step_id"`
type SignalMessage struct {
SignalID string `cbor:"signal_id"`
Data any `cbor:"data"`
}

func (s signalMessage) ToInput() schema.Input {
return schema.Input{ID: s.SignalID, InputData: s.Data}
func (s SignalMessage) ToInput(runID string) schema.Input {
return schema.Input{RunID: runID, ID: s.SignalID, InputData: s.Data}
}

type clientDoneMessage struct {
// Empty for now.
}

type ErrorMessage struct {
Error string `cbor:"error"`
StepFatal bool `cbor:"step_fatal"`
ServerFatal bool `cbor:"server_fatal"`
}

func (e ErrorMessage) ToString(runID string) string {
return fmt.Sprintf("RunID: %s, err: %s, step fatal: %t, server fatal: %t", runID, e.Error, e.StepFatal, e.ServerFatal)
}
Loading
Loading