mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-04 07:39:43 -06:00
* refactor: remove fks from unchanged/non-cascading parent tables * fix: cleanup cache for engine repository * fix: remove streamevent
76 lines
1.4 KiB
Go
76 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/hatchet-dev/hatchet/pkg/client"
|
|
"github.com/hatchet-dev/hatchet/pkg/repository/prisma/db"
|
|
"github.com/hatchet-dev/hatchet/pkg/worker"
|
|
)
|
|
|
|
func run(done chan<- string, job worker.WorkflowJob) (func() error, error) {
|
|
c, err := client.New()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error creating client: %w", err)
|
|
}
|
|
|
|
w, err := worker.NewWorker(
|
|
worker.WithClient(
|
|
c,
|
|
),
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error creating worker: %w", err)
|
|
}
|
|
|
|
err = w.On(
|
|
worker.Events("user:create:timeout"),
|
|
&job,
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error registering workflow: %w", err)
|
|
}
|
|
|
|
go func() {
|
|
log.Printf("pushing event")
|
|
|
|
testEvent := userCreateEvent{
|
|
Username: "echo-test",
|
|
UserID: "1234",
|
|
Data: map[string]string{
|
|
"test": "test",
|
|
},
|
|
}
|
|
|
|
// push an event
|
|
err := c.Event().Push(
|
|
context.Background(),
|
|
"user:create:timeout",
|
|
testEvent,
|
|
)
|
|
if err != nil {
|
|
panic(fmt.Errorf("error pushing event: %w", err))
|
|
}
|
|
|
|
time.Sleep(20 * time.Second)
|
|
|
|
client := db.NewClient()
|
|
if err := client.Connect(); err != nil {
|
|
panic(fmt.Errorf("error connecting to database: %w", err))
|
|
}
|
|
defer client.Disconnect()
|
|
|
|
done <- "done"
|
|
}()
|
|
|
|
cleanup, err := w.Start()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error starting worker: %w", err)
|
|
}
|
|
|
|
return cleanup, nil
|
|
}
|