Skip to content

Commit

Permalink
Change approach for SDK (#59)
Browse files Browse the repository at this point in the history
resolves #58 

Change the execution model to match the other SDKs.
The current attempt is not flexible at all.

Also update it to follow TS SDK v3 convention.

- execute function
- step run
- step sleep
- step sleep_until
- step wait_for_event
- step send_event
  • Loading branch information
darwin67 authored Nov 5, 2023
1 parent 44b9086 commit 300e907
Show file tree
Hide file tree
Showing 19 changed files with 951 additions and 1,299 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ jobs:
run: make deps

- name: Run tests with coverage
run: mix coveralls.github
run: mix coveralls.json
env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

formatter:
name: Formatter
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ changelog:

.PHONY: inngest-dev
inngest-dev:
inngest-cli dev -u http://127.0.0.1:4000/api/inngest
inngest-cli dev -v -u http://127.0.0.1:4000/api/inngest
63 changes: 33 additions & 30 deletions dev/event.ex
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
defmodule Inngest.Dev.EventFn do
defmodule Inngest.Dev.EventFn2 do
@moduledoc false

use Inngest.Function,
name: "test func",
event: "test/event"
use Inngest.Function
alias Inngest.{FnOpts, Trigger}

# batch_events: %{max_size: 3, timeout: "10s"}
@func %FnOpts{id: "test-func-v2", name: "test func v2"}
@trigger %Trigger{event: "test/hello"}

run "test 1st run" do
{:ok, %{run: "do something"}}
end
@impl true
def exec(ctx, %{run_id: run_id, step: step} = _args) do
IO.inspect("First log")

step "test 1st step" do
{:ok, %{hello: "world"}}
end
greet =
step.run(ctx, "hello", fn ->
"Hello world"
end)
|> IO.inspect()

sleep "2s"
step.sleep(ctx, "sleep-test", "10s")
# step.sleep(ctx, "sleep-until-test", "2023-11-05T00:12:00Z")

step "test 2nd step" do
{:ok, 100}
end
IO.inspect("Second log")

sleep "2s"
# sleep "until 1m later" do
# "2023-07-18T07:31:00Z"
# end

step "test 3rd - state accumulate" do
{:ok, %{result: "ok"}}
end
# step.wait_for_event(ctx, "wait-test", %{
# event: "test/yolo",
# timeout: "1h"
# # match: "data.foo"
# })
# |> IO.inspect()

# wait_for_event "test/wait" do
# match = "data.yo"
# [timeout: "1d", if: "event.#{match} == async.#{match}"]
# end
step.send_event(ctx, "test-event-sending", %{
name: "test/foobar",
data: %{"foo" => "bar"}
})
|> IO.inspect()

# wait_for_event "test/wait", do: [timeout: "1d", match: "data.yo"]
name =
step.run(ctx, "name", fn ->
"John Doe"
end)
|> IO.inspect()

run "result", %{data: data} do
{:ok, data}
{:ok, "#{greet} #{name}"} |> IO.inspect()
end
end
11 changes: 0 additions & 11 deletions dev/scheduled/cron.ex

This file was deleted.

5 changes: 4 additions & 1 deletion lib/inngest/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ end

defimpl Jason.Encoder, for: Inngest.Event do
def encode(value, opts) do
Jason.Encode.map(Map.from_struct(value), opts)
value
|> Map.from_struct()
|> Map.drop([:datetime])
|> Jason.Encode.map(opts)
end
end
Loading

0 comments on commit 300e907

Please sign in to comment.