Skip to content

Commit f805683

Browse files
committed
update cron config
1 parent d15d4ea commit f805683

File tree

8 files changed

+87
-423
lines changed

8 files changed

+87
-423
lines changed

go.mod

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ require (
1919
)
2020

2121
require (
22-
github.com/abiosoft/ishell/v2 v2.0.2
23-
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db
2422
github.com/caddyserver/certmagic v0.25.2
2523
github.com/charmbracelet/ssh v0.0.0-20250826160808-ebfa259c7309
2624
github.com/charmbracelet/wish v1.4.7
@@ -64,7 +62,6 @@ require (
6462
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.55.0 // indirect
6563
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.55.0 // indirect
6664
github.com/ProtonMail/go-crypto v1.4.0 // indirect
67-
github.com/abiosoft/ishell v2.0.0+incompatible // indirect
6865
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
6966
github.com/aws/aws-sdk-go-v2 v1.41.2 // indirect
7067
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.5 // indirect
@@ -100,22 +97,19 @@ require (
10097
github.com/charmbracelet/x/ansi v0.11.6 // indirect
10198
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
10299
github.com/charmbracelet/x/conpty v0.2.0 // indirect
103-
github.com/charmbracelet/x/errors v0.0.0-20260301003739-baafbde16d0a // indirect
104100
github.com/charmbracelet/x/term v0.2.2 // indirect
105101
github.com/charmbracelet/x/termios v0.1.1 // indirect
106102
github.com/clipperhouse/displaywidth v0.11.0 // indirect
107-
github.com/clipperhouse/stringish v0.1.1 // indirect
108103
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
109104
github.com/cloudflare/circl v1.6.3 // indirect
110105
github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2 // indirect
111106
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
112-
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
107+
github.com/danielgtaylor/huma/v2 v2.37.2 // indirect
113108
github.com/envoyproxy/go-control-plane/envoy v1.37.0 // indirect
114109
github.com/envoyproxy/protoc-gen-validate v1.3.3 // indirect
115110
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
116111
github.com/fatih/color v1.18.0 // indirect
117112
github.com/felixge/httpsnoop v1.0.4 // indirect
118-
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
119113
github.com/getsops/gopgagent v0.0.0-20241224165529-7044f28e491e // indirect
120114
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
121115
github.com/go-logfmt/logfmt v0.6.1 // indirect
@@ -144,6 +138,7 @@ require (
144138
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.187 // indirect
145139
github.com/inconshreveable/mousetrap v1.1.0 // indirect
146140
github.com/json-iterator/go v1.1.13-0.20220915233716-71ac16282d12 // indirect
141+
github.com/julienschmidt/httprouter v1.3.0 // indirect
147142
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
148143
github.com/knadh/koanf/maps v0.1.2 // indirect
149144
github.com/kr/fs v0.1.0 // indirect
@@ -170,9 +165,7 @@ require (
170165
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
171166
github.com/pkg/errors v0.9.1 // indirect
172167
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
173-
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
174168
github.com/rivo/uniseg v0.4.7 // indirect
175-
github.com/rogpeppe/go-internal v1.14.1 // indirect
176169
github.com/russross/blackfriday/v2 v2.1.0 // indirect
177170
github.com/ryanuber/go-glob v1.0.0 // indirect
178171
github.com/sirupsen/logrus v1.9.4 // indirect
@@ -203,13 +196,11 @@ require (
203196
golang.org/x/text v0.34.0 // indirect
204197
golang.org/x/time v0.14.0 // indirect
205198
golang.org/x/tools v0.42.0 // indirect
206-
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
207199
google.golang.org/api v0.269.0 // indirect
208200
google.golang.org/genproto v0.0.0-20260226221140-a57be14db171 // indirect
209201
google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171 // indirect
210202
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 // indirect
211203
google.golang.org/grpc v1.79.1 // indirect
212204
google.golang.org/protobuf v1.36.11 // indirect
213205
gopkg.in/ini.v1 v1.67.1 // indirect
214-
gopkg.in/yaml.v3 v3.0.1 // indirect
215206
)

go.sum

Lines changed: 19 additions & 313 deletions
Large diffs are not rendered by default.

internal/app/app.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ type App struct {
4747

4848
func (me *App) Dir() string {
4949
dir := me.BaseDir
50-
if fi, err := os.Lstat(dir); err == nil && fi.Mode()&os.ModeSymlink != 0 {
51-
if root, err := os.Readlink(dir); err == nil {
52-
dir = filepath.Join(filepath.Dir(dir), root)
53-
}
54-
}
5550

5651
if me.Config.Root != "" {
5752
return filepath.Join(dir, me.Config.Root)
@@ -80,17 +75,6 @@ func (me *App) Dir() string {
8075
return dir
8176
}
8277

83-
func (me *App) DataDir() string {
84-
dir := filepath.Join(me.Dir(), "data")
85-
if fi, err := os.Lstat(dir); err == nil && fi.Mode()&os.ModeSymlink != 0 {
86-
if root, err := os.Readlink(dir); err == nil {
87-
dir = filepath.Join(filepath.Dir(dir), root)
88-
}
89-
}
90-
91-
return dir
92-
}
93-
9478
func LookupApps(rootDir string) ([]string, error) {
9579
entries, err := os.ReadDir(rootDir)
9680
if err != nil {

internal/cmd/crons.go

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,25 @@ type CronItem struct {
2121
app.CronJob
2222
}
2323

24-
func NewCmdCrons() *cobra.Command {
24+
func NewCmdCron() *cobra.Command {
25+
cmd := &cobra.Command{
26+
Use: "cron",
27+
}
28+
29+
cmd.AddCommand(NewCmdCronList())
30+
cmd.AddCommand(NewCmdCronTrigger())
31+
32+
return cmd
33+
}
34+
35+
func NewCmdCronList() *cobra.Command {
2536
var flags struct {
2637
json bool
2738
app string
2839
}
2940

3041
cmd := &cobra.Command{
31-
Use: "crons [app]",
42+
Use: "list",
3243
Aliases: []string{"cron"},
3344
Short: "List cron jobs",
3445
ValidArgsFunction: completeApp,
@@ -154,8 +165,8 @@ func CronRunner(logger *slog.Logger) *cron.Cron {
154165

155166
logger.Info("running cron job", "app", appname, "name", job.Name, "schedule", job.Schedule)
156167
go func() {
157-
if err := wk.TriggerCron(context.Background(), job.Name); err != nil {
158-
logger.Error("failed to run command", "app", appname, "name", job.Name, "error", err)
168+
if err := wk.TriggerCron(context.Background(), job); err != nil {
169+
logger.Error("failed to run command", "app", appname, "name", job.Name, "schedule", job.Schedule, "error", err)
159170
}
160171
}()
161172
}
@@ -164,3 +175,41 @@ func CronRunner(logger *slog.Logger) *cron.Cron {
164175

165176
return c
166177
}
178+
179+
func NewCmdCronTrigger() *cobra.Command {
180+
var flags struct {
181+
app string
182+
}
183+
184+
cmd := &cobra.Command{
185+
Use: "trigger <name>",
186+
Args: cobra.ExactArgs(1),
187+
RunE: func(cmd *cobra.Command, args []string) error {
188+
a, err := app.LoadApp(flags.app, k.String("dir"), k.String("domain"))
189+
if err != nil {
190+
return ExitError{1}
191+
}
192+
193+
var job *app.CronJob
194+
for _, j := range a.Config.Crons {
195+
if j.Name == args[0] {
196+
job = &j
197+
break
198+
}
199+
}
200+
201+
if job == nil {
202+
return ExitError{1}
203+
}
204+
205+
wk := worker.NewWorker(a, nil)
206+
if err := wk.TriggerCron(cmd.Context(), *job); err != nil {
207+
return ExitError{1}
208+
}
209+
210+
return nil
211+
},
212+
}
213+
214+
return cmd
215+
}

internal/cmd/link.go

Lines changed: 0 additions & 73 deletions
This file was deleted.

internal/cmd/root.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,9 @@ func NewCmdRoot() *cobra.Command {
156156
rootCmd.AddCommand(NewCmdUp())
157157
rootCmd.AddCommand(NewCmdDoctor())
158158
rootCmd.AddCommand(NewCmdList())
159-
rootCmd.AddCommand(NewCmdCrons())
159+
rootCmd.AddCommand(NewCmdCron())
160160
rootCmd.AddCommand(NewCmdInit())
161161
rootCmd.AddCommand(NewCmdConfig())
162-
rootCmd.AddCommand(NewCmdLink())
163162
rootCmd.AddCommand(NewCmdGitReceivePack())
164163
rootCmd.AddCommand(NewCmdGitUploadPack())
165164

internal/worker/worker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ func DenoExecutable() (string, error) {
442442
return "", fmt.Errorf("deno executable not found")
443443
}
444444

445-
func (me *Worker) TriggerCron(ctx context.Context, name string) error {
445+
func (me *Worker) TriggerCron(ctx context.Context, job app.CronJob) error {
446446
deno, err := DenoExecutable()
447447
if err != nil {
448448
return fmt.Errorf("could not find deno executable")
@@ -461,7 +461,8 @@ func (me *Worker) TriggerCron(ctx context.Context, name string) error {
461461
if err := encoder.Encode(map[string]any{
462462
"command": "cron",
463463
"entrypoint": me.App.Entrypoint(),
464-
"name": name,
464+
"name": job.Name,
465+
"schedule": job.Schedule,
465466
}); err != nil {
466467
return fmt.Errorf("could not encode input: %w", err)
467468
}

schemas/config.schema.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
},
1212
"additionalDomains": {
1313
"description": "Additional wildcard domains",
14-
"type": "array",
15-
"items": {
14+
"type": "object",
15+
"additionalProperties": {
1616
"type": "string"
1717
}
1818
},
@@ -22,6 +22,13 @@
2222
"items": {
2323
"type": "string"
2424
}
25+
},
26+
"authorizedTokens": {
27+
"description": "Authorized API tokens",
28+
"type": "array",
29+
"items": {
30+
"type": "string"
31+
}
2532
}
2633
}
2734
}

0 commit comments

Comments
 (0)