diff --git a/dev/event.ex b/dev/event.ex index 20c954d..dd0dbf7 100644 --- a/dev/event.ex +++ b/dev/event.ex @@ -22,10 +22,16 @@ defmodule Inngest.Dev.EventFn2 do IO.inspect("Second log") - step.wait_for_event(ctx, "wait-test", %{ - event: "test/yolo", - timeout: "1h" - # match: "data.foo" + # step.wait_for_event(ctx, "wait-test", %{ + # event: "test/yolo", + # timeout: "1h" + # # match: "data.foo" + # }) + # |> IO.inspect() + + step.send_event(ctx, "test-event-sending", %{ + name: "test/foobar", + data: %{"foo" => "bar"} }) |> IO.inspect() diff --git a/lib/inngest/event.ex b/lib/inngest/event.ex index c82d02a..435502b 100644 --- a/lib/inngest/event.ex +++ b/lib/inngest/event.ex @@ -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 diff --git a/lib/inngest/step_tool.ex b/lib/inngest/step_tool.ex index 6e6fa9e..165668d 100644 --- a/lib/inngest/step_tool.ex +++ b/lib/inngest/step_tool.ex @@ -115,6 +115,33 @@ defmodule Inngest.StepTool do end end - def send_event() do + def send_event(%{steps: steps} = _ctx, step_id, events) do + op = %UnhashedOp{name: step_id, op: "Step"} + hashed_id = UnhashedOp.hash(op) + + case Map.get(steps, hashed_id) do + nil -> + display_name = + cond do + is_map(events) -> Map.get(events, :name, step_id) + true -> step_id + end + + # if not, execute function + result = Inngest.Client.send(events) + + # cancel execution and return with opcode + throw(%GeneratorOpCode{ + id: hashed_id, + name: "sendEvent", + display_name: "Send " <> display_name, + op: op.op, + data: result + }) + + # if found, return value + val -> + val + end end end