main
Efertone 2 years ago
parent e54337b86d
commit d26aa0680e
Signed by: efertone
GPG Key ID: 58E2D23885002DC5

@ -2,8 +2,10 @@ package main
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"reflect"
"time"
@ -14,6 +16,8 @@ import (
func init() {
flows.RegisterAction(findTorrents)
flows.RegisterAction(dropExistingTorrents)
flows.RegisterAction(transformStat)
flows.RegisterAction(combine)
}
func main() {
@ -22,16 +26,67 @@ func main() {
flows.Debug(true)
}
type Response struct {
Result Result
Error string
}
type Result struct {
Instances uint64
NotesCount uint64
UsersCount uint64
OriginalNotesCount uint64
OriginalUsersCount uint64
DriveUsageLocal uint64
DriveUsageRemote uint64
}
type NoteDiff struct {
Before uint64
After uint64
Diff uint64
}
func transformStat(resp *flows.HTTPResponse) flows.FlowFuture {
response := Response{}
json.Unmarshal(resp.Body, &response)
return flows.CurrentFlow().CompletedValue(response.Result)
}
func combine(first, second Result) flows.FlowFuture {
diff := NoteDiff{
Before: first.NotesCount,
After: second.NotesCount,
Diff: second.NotesCount - first.NotesCount,
}
return flows.CurrentFlow().CompletedValue(diff)
}
func flowHandler() fdk.Handler {
return flows.WithFlow(
fdk.HandlerFunc(func(ctx context.Context, r io.Reader, w io.Writer) {
flow := flows.CurrentFlow()
wf := flow.CompletedValue("something").
ThenCompose(findTorrents).
ThenCompose(dropExistingTorrents)
// wf := flow.CompletedValue("something").
// ThenCompose(findTorrents).
// ThenCompose(dropExistingTorrents)
firstStat := flow.InvokeFunction(
"01F18NYY1S18000HG0A0000001",
&flows.HTTPRequest{Method: http.MethodPost, Body: []byte("{}")},
).ThenCompose(transformStat)
secondStat := flow.InvokeFunction(
"01F18NYY1S18000HG0A0000001",
&flows.HTTPRequest{Method: http.MethodPost, Body: []byte("{}")},
).ThenCompose(transformStat)
final := firstStat.ThenCombine(secondStat, combine)
valueCh, errorCh := wf.GetType(reflect.TypeOf([]string{}))
valueCh, errorCh := final.GetType(reflect.TypeOf(NoteDiff{}))
printResult(w, valueCh, errorCh)
}),

@ -1,6 +1,6 @@
schema_version: 20180708
name: flowtest
version: 0.0.44
version: 0.0.63
runtime: go
build_image: golang:1.16-alpine
run_image: alpine:3.13

Loading…
Cancel
Save