Skip to content

Commit

Permalink
checkpoint before removing calls to t.Value()
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Worm <tony@hofstadter.io>
  • Loading branch information
verdverm committed Jan 30, 2022
1 parent 4efb003 commit b76184e
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 52 deletions.
31 changes: 20 additions & 11 deletions examples/streamer/auth/twitch.cue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// This pipeline gets an api code with OAuth workflow
package auth

import (
"encoding/json"
Expand All @@ -7,15 +8,29 @@ import (
"github.com/hofstadter-io/cuetils/examples/utils"
)

// This pipeline will load a saved token
// for making calls to the Twitch API
load: {
@pipeline(load,auth)

cfg: meta

files: {
token_txt: { filename: cfg.vars.token_fn } @task(os.ReadFile)
token_json: json.Unmarshal(token_txt.contents)
}
data: files.token_json
token: data.access_token
}

meta: {
@pipeline(meta)
@pipeline(meta,auth)

vars: {
r: utils.RepoRoot
root: r.Out
code_fn: "\(vars.root)/examples/streamer/secrets/twitch.code"
token_fn: "\(vars.root)/examples/streamer/secrets/twitch.json"
code_fn: "\(root)/examples/streamer/secrets/twitch.code"
token_fn: "\(root)/examples/streamer/secrets/twitch.json"
}

secrets: {
Expand Down Expand Up @@ -57,17 +72,11 @@ meta: {
}
}

// This pipeline will load a saved token
// for making calls to the Twitch API
load_token: {
@pipeline(load)

}

// This pipeline will run the OAuth workflow
// go get a new token for the Twitch API
get_token: {
@pipeline(get)
@pipeline(get,auth)

cfg: meta

Expand All @@ -83,7 +92,7 @@ get_token: {
}

server: {
@pipeline(server)
@pipeline(server,auth/get)

run: {
@task(api.Serve)
Expand Down
14 changes: 10 additions & 4 deletions examples/streamer/twitch/chat.cue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This pipeline listens to the channel chat
// and does things, hopefully
package twitch

import "strings"

Expand All @@ -12,21 +13,25 @@ links: {
github: "https://github.com/hofstadter-io"
hof: "https://github.com/hofstadter-io/hof"
cuetils: "https://github.com/hofstadter-io/cuetils"
neoverm: "https://github.com/verdverm/neoverm"

neoverm: "https://github.com/verdverm/neoverm"
grasshopper: "https://grasshopper.app/"
}

respHandlers: {
"!today": "working on a twitch bot in CUEtils pipelines"
"!music": "streaming https://www.youtube.com/watch?v=udGvUx70Q3U"
"!go-learn": "Checkout my currated links: https://verdverm.com/resources/learning-go"
"!github": links.github
"!hof": links.hof
"!cuetils": links.cuetils
"!vim": links.neoverm
"!nvim": links.neoverm
"!neovim": links.neoverm
"!neoverm": links.neoverm
"!dox": "google 'verdverm'"

"!grasshopper": links.grasshopper
"!learn/code": "Try out the Grasshopper App \(links.grasshopper)"
"!learn/go": "Checkout my currated links: https://verdverm.com/resources/learning-go"
}

meta: {
Expand Down Expand Up @@ -130,7 +135,7 @@ pipeHandlers: {
stdout: string
}

chill: { duration: "4s" } @task(os.Sleep)
// chill: { duration: "4s" } @task(os.Sleep)

lines: strings.Split(get.stdout, "\n")
count: len(lines) - 1
Expand All @@ -148,6 +153,7 @@ pipeHandlers: {
// call twitch api for info about the user
// eventually also look up custom data in DB
}
// chill: { duration: "4s" } @task(os.Sleep)

resp: "you're the best \(who)"

Expand Down
37 changes: 17 additions & 20 deletions examples/streamer/twitch/info.cue
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// This pipeline gets an api code with OAuth workflow
package twitch

import (
"encoding/json"
"strings"

"github.com/hofstadter-io/cuetils/examples/utils"
"github.com/hofstadter-io/cuetils/examples/streamer/auth"
)

vars: {
Expand All @@ -21,15 +19,18 @@ meta: {
}
cid: env.TWITCH_CLIENT_ID

r: utils.RepoRoot
root: r.Out
token_fn: "\(root)/examples/streamer/secrets/twitch.json"
// r: utils.RepoRoot
// root: r.Out
// token_fn: "\(root)/examples/streamer/secrets/twitch.json"

files: {
token_txt: { filename: token_fn } @task(os.ReadFile)
token_json: json.Unmarshal(token_txt.contents)
}
token: files.token_json.access_token
// files: {
// token_txt: { filename: token_fn } @task(os.ReadFile)
// token_json: json.Unmarshal(token_txt.contents)
// }
// token: files.token_json.access_token

tLoad: auth.load
token: tLoad.token
}

twitch_req: {
Expand All @@ -45,21 +46,17 @@ meta: {

user: {
@pipeline(user)

cfg: meta

ucfg: meta
get: {
@task(api.Call)
req: cfg.twitch_req & {
req: ucfg.twitch_req & {
path: "/helix/users"
query: {
login: vars.user
}
}
}

id: get.resp.data[0].id
print: { text: id + "\n" } @task(os.Stdout)
}
print: { text: get.resp.data[0].id + "\n" } @task(os.Stdout)
}

title: {
Expand Down
168 changes: 168 additions & 0 deletions examples/streamer/twitch/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
$ _cp twitch/info.cue -p user
pipe(beg): user
PIPE: @pipeline(user)
PIPE: @pipeline(meta) ucfg
++PP: @pipeline(meta) ucfg
TASK: @task(api.Call) get
TASK: @task(os.Stdout) print
pipe(beg): ucfg
PIPE: @pipeline(meta)
TASK: @task(os.Getenv) secrets.env.TWITCH_CLIENT_ID
PIPE: @pipeline(load,auth) secrets.tLoad
++PP: @pipeline(load,auth) secrets.tLoad
pipe(beg): secrets.tLoad
pipe(end): ucfg
PIPE: @pipeline(load,auth)
pipe(end): user
Error: task failed: Error: secrets.tLoad.cfg: structural cycle
... or ...
Error: task failed: Error: secrets.tLoad.cfg.r: structural cycle


$ _cp twitch/info.cue -p user
pipe(beg): user
PIPE: @pipeline(user)
PIPE: @pipeline(meta) ucfg
++PP: @pipeline(meta) ucfg
TASK: @task(api.Call) get
TASK: @task(os.Stdout) print
pipe(beg): ucfg
PIPE: @pipeline(meta)
TASK: @task(os.Getenv) secrets.env.TWITCH_CLIENT_ID
PIPE: @pipeline(load,auth) secrets.tLoad
++PP: @pipeline(load,auth) secrets.tLoad
pipe(beg): secrets.tLoad
PIPE: @pipeline(load,auth)
PIPE: @pipeline(meta,auth) cfg
++PP: @pipeline(meta,auth) cfg
TASK: @task(os.ReadFile) files.token_txt
PIPE: @pipeline(meta)
pipe(beg): cfg
PIPE: @pipeline(meta,auth)
PIPE: @pipeline(reporoot) vars.r
++PP: @pipeline(reporoot) vars.r
TASK: @task(os.Getenv) secrets.env.TWITCH_CLIENT_ID
TASK: @task(os.Getenv) secrets.env.TWITCH_SECRET_KEY
PIPE: @pipeline(meta,auth)
pipe(beg): vars.r RepoRoot
PIPE: @pipeline(reporoot)
TASK: @task(os.Exec) do
PIPE: @pipeline(meta,auth)
PIPE: @pipeline(reporoot)
pipe(end): vars.r RepoRoot
PIPE: @pipeline(meta,auth)
pipe(end): cfg
PIPE: @pipeline(load,auth)
PIPE: @pipeline(load,auth)
pipe(end): secrets.tLoad
PIPE: @pipeline(meta)
pipe(end): ucfg
PIPE: @pipeline(user)
PIPE: @pipeline(user)
696471067
pipe(end): user
===============


$ _cp twitch/info.cue -p user
pipe(beg): user
pipe(beg): ucfg
pipe(beg): secrets.tLoad
pipe(end): ucfg
pipe(end): user
Error: task failed: Error: secrets.tLoad: structural cycle


$ _cp twitch/info.cue -p user
pipe(beg): user
pipe(beg): ucfg
pipe(beg): secrets.tLoad
pipe(end): ucfg
pipe(end): user
Error: task failed: Error: secrets.tLoad.cfg: structural cycle


$ _cp twitch/info.cue -p user
pipe(beg): user
pipe(beg): ucfg
pipe(beg): secrets.tLoad
pipe(beg): cfg
pipe(beg): vars.r RepoRoot
pipe(end): vars.r RepoRoot
pipe(end): cfg
pipe(end): secrets.tLoad
pipe(end): ucfg
696471067
pipe(end): user


=======


$ _cp twitch/info.cue -p user
pipe(beg): user
PIPE: @pipeline(user)
PIPE: @pipeline(meta) ucfg
TASK: @task(api.Call) get
TASK: @task(os.Stdout) print
pipe(beg): ucfg
PIPE: @pipeline(meta)
TASK: @task(os.Getenv) secrets.env.TWITCH_CLIENT_ID
PIPE: @pipeline(load,auth) secrets.tLoad
pipe(beg): secrets.tLoad
PIPE: @pipeline(load,auth)
PIPE: @pipeline(meta,auth) cfg
TASK: @task(os.ReadFile) files.token_txt
pipe(beg): cfg
PIPE: @pipeline(meta,auth)
PIPE: @pipeline(reporoot) vars.r
TASK: @task(os.Getenv) secrets.env.TWITCH_CLIENT_ID
TASK: @task(os.Getenv) secrets.env.TWITCH_SECRET_KEY
PIPE: @pipeline(meta,auth)
pipe(beg): vars.r RepoRoot
PIPE: @pipeline(reporoot)
TASK: @task(os.Exec) do
pipe(end): ucfg
PIPE: @pipeline(meta,auth)
pipe(end): user
Error: task failed: Error: secrets.tLoad: structural cycle


$ _cp twitch/info.cue -p user
pipe(beg): user
PIPE: @pipeline(user)
PIPE: @pipeline(meta) ucfg
TASK: @task(api.Call) get
TASK: @task(os.Stdout) print
pipe(beg): ucfg
PIPE: @pipeline(meta)
TASK: @task(os.Getenv) secrets.env.TWITCH_CLIENT_ID
PIPE: @pipeline(load,auth) secrets.tLoad
pipe(beg): secrets.tLoad
PIPE: @pipeline(load,auth)
PIPE: @pipeline(meta,auth) cfg
TASK: @task(os.ReadFile) files.token_txt
pipe(beg): cfg
PIPE: @pipeline(meta,auth)
PIPE: @pipeline(reporoot) vars.r
PIPE: @pipeline(meta)
TASK: @task(os.Getenv) secrets.env.TWITCH_CLIENT_ID
TASK: @task(os.Getenv) secrets.env.TWITCH_SECRET_KEY
pipe(beg): vars.r RepoRoot
PIPE: @pipeline(meta,auth)
PIPE: @pipeline(reporoot)
TASK: @task(os.Exec) do
PIPE: @pipeline(meta,auth)
PIPE: @pipeline(reporoot)
pipe(end): vars.r RepoRoot
PIPE: @pipeline(meta,auth)
pipe(end): cfg
PIPE: @pipeline(load,auth)
PIPE: @pipeline(load,auth)
pipe(end): secrets.tLoad
PIPE: @pipeline(meta)
pipe(end): ucfg
PIPE: @pipeline(user)
PIPE: @pipeline(user)
696471067
pipe(end): user
5 changes: 5 additions & 0 deletions examples/tmp/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"foo": "bar",
"cow": "moo"
}

Loading

0 comments on commit b76184e

Please sign in to comment.