mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
pkg/sdk/examples/{hello,signal,cron}.go drive the engine end-to-end
through pkg/sdk/client over the ZAP wire — zero HTTP, zero
go.temporal.io. Tests boot tasks.Embed in-process, dial the local
ZAP node, and round-trip every workflow + schedule opcode.
Engine fixes (pkg/tasks/embed.go):
- ZAP handlers now read the SDK's snake_case JSON shape
(workflow_id / workflow_type / task_queue / signal_name / schedule_id)
in addition to the camelCase shape used by the HTTP shim
- DescribeWorkflow returns {info: WorkflowExecutionInfo} (SDK shape)
- WorkflowExecutionInfo emits status as int8 (1=RUNNING / 4=CANCELED / 5=TERMINATED)
- StartWorkflow returns {run_id, workflow_id}
- PauseSchedule respects the requested paused flag (was always true)
- Schedule list response goes through scheduleSDK marshaller
- Empty time.Time fields are omitted (SDK can't parse "")
Store fix:
- store.list() snapshots under RLock then iterates without lock,
preventing the RWMutex upgrade deadlock that hung GET /v1/tasks/...
whenever the cron sweeper's put() was waiting on a Lock that
competed with reader RLocks
go test ./pkg/sdk/examples/... → 4/4 PASS:
TestHealth, TestHello, TestSignal, TestCron
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
// Copyright © 2026 Hanzo AI. MIT License.
|
|
|
|
package examples
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/hanzoai/tasks/pkg/sdk/client"
|
|
)
|
|
|
|
type CronResult struct {
|
|
ScheduleID string
|
|
ListedCount int
|
|
Paused bool
|
|
Resumed bool
|
|
}
|
|
|
|
// Cron creates a schedule, lists schedules, pauses + unpauses it,
|
|
// then deletes it.
|
|
func Cron(ctx context.Context, c client.Client, _ string) (*CronResult, error) {
|
|
id := "cron-" + time.Now().UTC().Format("150405.000000")
|
|
if err := c.CreateSchedule(ctx, client.CreateScheduleOptions{
|
|
ID: id,
|
|
CronExpressions: []string{"0 3 * * *"},
|
|
WorkflowType: "DailyCleanup",
|
|
TaskQueue: "schedules",
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
res := &CronResult{ScheduleID: id}
|
|
|
|
list, err := c.ListSchedules(ctx, 100, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if list != nil {
|
|
for _, s := range list.Schedules {
|
|
if s.ID == id {
|
|
res.ListedCount++
|
|
}
|
|
}
|
|
}
|
|
|
|
if err := c.PauseSchedule(ctx, id, true); err == nil {
|
|
res.Paused = true
|
|
}
|
|
if err := c.UnpauseSchedule(ctx, id); err == nil {
|
|
res.Resumed = true
|
|
}
|
|
|
|
_ = c.DeleteSchedule(ctx, id)
|
|
return res, nil
|
|
}
|