arcrun — AI workflow execution engine (clean history)
Self-hosted 開源:WASM 零件 + recipe + cypher-executor,跑在你自己的 Cloudflare。 此為重建的乾淨歷史起點(移除曾誤 commit 的 GCP SA 金鑰,舊歷史保留在 richblack/arcrun 與本地 backup 分支)。含: - acr init --self-hosted installer(建 KV/R2 + codeload 拉預編譯 wasm + wrangler deploy + seed recipe) - recipe push 把關(資料外流提醒 + 打通檢查) - 19 個正當零件預編譯 wasm(claude_api/km_writer/kbdb_upsert_block 排除:違反 DECISIONS §1) - CLI / cypher-executor / registry / 完整 SDD Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
canonical_id: "cron"
|
||||
display_name: "定時排程"
|
||||
category: "logic"
|
||||
version: "v1"
|
||||
wasi_target: "preview1"
|
||||
stability: "floating"
|
||||
runtime_compat:
|
||||
- "cf-workers"
|
||||
- "workerd"
|
||||
- "wazero"
|
||||
constraints:
|
||||
max_size_kb: 2048
|
||||
max_cold_start_ms: 50
|
||||
no_network_syscall: true
|
||||
no_filesystem_syscall: true
|
||||
io_model: "stdin_stdout_json"
|
||||
input_schema:
|
||||
type: object
|
||||
required: [cron_expr]
|
||||
properties:
|
||||
cron_expr:
|
||||
type: string
|
||||
description: 標準 5 欄位 cron expression,如 0 9 * * *
|
||||
description:
|
||||
type: string
|
||||
output_schema:
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
data:
|
||||
type: object
|
||||
properties:
|
||||
cron_id:
|
||||
type: string
|
||||
cron_expr:
|
||||
type: string
|
||||
enabled:
|
||||
type: boolean
|
||||
description:
|
||||
type: string
|
||||
gherkin_tests:
|
||||
- scenario: "有效 cron expression"
|
||||
given: '{"cron_expr":"0 9 * * *","description":"每天早上9點"}'
|
||||
then_contains: '"enabled":true'
|
||||
- scenario: "無效 cron expression(欄位數不對)"
|
||||
given: '{"cron_expr":"0 9 * *"}'
|
||||
then_contains: '{"success":false'
|
||||
- scenario: "缺少 cron_expr"
|
||||
given: '{}'
|
||||
then_contains: '{"success":false'
|
||||
tags: [builtin, cron, schedule, trigger, timer]
|
||||
description: "驗證 cron expression 格式並回傳 cron_id。實際排程由 Cypher Executor 負責。"
|
||||
config_example: |
|
||||
my_cron: # 節點名稱(可自訂)
|
||||
cron_expr: "0 9 * * *" # 標準 5 欄位 cron 表達式(必填),如:每天早上 9 點
|
||||
description: "每天早上9點執行" # 排程說明文字(選填)
|
||||
@@ -0,0 +1,3 @@
|
||||
module component
|
||||
|
||||
go 1.21
|
||||
@@ -0,0 +1,123 @@
|
||||
// cron — 驗證 cron expression 格式,回傳 cron_id
|
||||
// 實際排程由 Cypher Executor 負責
|
||||
//
|
||||
//go:build tinygo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Input struct {
|
||||
CronExpr string `json:"cron_expr"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
raw, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
writeError("failed to read stdin: " + err.Error())
|
||||
return
|
||||
}
|
||||
var input Input
|
||||
if err := json.Unmarshal(raw, &input); err != nil {
|
||||
writeError("invalid input JSON: " + err.Error())
|
||||
return
|
||||
}
|
||||
if input.CronExpr == "" {
|
||||
writeError("cron_expr 必填")
|
||||
return
|
||||
}
|
||||
|
||||
if err := validateCronExpr(input.CronExpr); err != nil {
|
||||
writeError("無效的 cron expression: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cronID := "cron-" + strconv.FormatInt(time.Now().UnixNano()/1e6, 10)
|
||||
|
||||
out, _ := json.Marshal(map[string]interface{}{
|
||||
"success": true,
|
||||
"data": map[string]interface{}{
|
||||
"cron_id": cronID,
|
||||
"cron_expr": input.CronExpr,
|
||||
"enabled": true,
|
||||
"description": input.Description,
|
||||
},
|
||||
})
|
||||
os.Stdout.Write(out)
|
||||
}
|
||||
|
||||
// validateCronExpr — 驗證標準 5 欄位 cron expression
|
||||
func validateCronExpr(expr string) error {
|
||||
fields := strings.Fields(expr)
|
||||
if len(fields) != 5 {
|
||||
return &cronError{"需要 5 個欄位(分 時 日 月 週),實際: " + strconv.Itoa(len(fields))}
|
||||
}
|
||||
|
||||
// 各欄位範圍: 分(0-59), 時(0-23), 日(1-31), 月(1-12), 週(0-7)
|
||||
ranges := [][2]int{{0, 59}, {0, 23}, {1, 31}, {1, 12}, {0, 7}}
|
||||
names := []string{"分鐘", "小時", "日", "月", "星期"}
|
||||
|
||||
for i, field := range fields {
|
||||
if err := validateCronField(field, ranges[i][0], ranges[i][1], names[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateCronField(field string, min, max int, name string) error {
|
||||
if field == "*" {
|
||||
return nil
|
||||
}
|
||||
// 支援 */n 格式
|
||||
if strings.HasPrefix(field, "*/") {
|
||||
n, err := strconv.Atoi(field[2:])
|
||||
if err != nil || n <= 0 {
|
||||
return &cronError{name + " 步進值無效: " + field}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// 支援 a-b 範圍
|
||||
if strings.Contains(field, "-") {
|
||||
parts := strings.SplitN(field, "-", 2)
|
||||
a, err1 := strconv.Atoi(parts[0])
|
||||
b, err2 := strconv.Atoi(parts[1])
|
||||
if err1 != nil || err2 != nil || a < min || b > max || a > b {
|
||||
return &cronError{name + " 範圍無效: " + field}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// 支援逗號分隔
|
||||
if strings.Contains(field, ",") {
|
||||
for _, part := range strings.Split(field, ",") {
|
||||
n, err := strconv.Atoi(part)
|
||||
if err != nil || n < min || n > max {
|
||||
return &cronError{name + " 值無效: " + part}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// 單一數字
|
||||
n, err := strconv.Atoi(field)
|
||||
if err != nil || n < min || n > max {
|
||||
return &cronError{name + " 值超出範圍 [" + strconv.Itoa(min) + "-" + strconv.Itoa(max) + "]: " + field}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type cronError struct{ msg string }
|
||||
|
||||
func (e *cronError) Error() string { return e.msg }
|
||||
|
||||
func writeError(msg string) {
|
||||
out, _ := json.Marshal(map[string]interface{}{"success": false, "error": msg})
|
||||
os.Stdout.Write(out)
|
||||
}
|
||||
Reference in New Issue
Block a user