Skip to content

Commit 3fabd00

Browse files
authored
Merge pull request #3 from AgentWorkforce/feat/relaycron-rewrite
Rename @agentcron to @relaycron, remove Cloudflare from server
2 parents de7bdc4 + 1282b77 commit 3fabd00

69 files changed

Lines changed: 40185 additions & 2830 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
added 46 packages, removed 77 packages, and audited 115 packages in 4s
3+
4+
37 packages are looking for funding
5+
run `npm fund` for details
6+
7+
2 vulnerabilities (1 moderate, 1 high)
8+
9+
To address issues that do not require attention, run:
10+
npm audit fix
11+
12+
To address all issues (including breaking changes), run:
13+
npm audit fix --force
14+
15+
Run `npm audit` for details.
16+
packages/server/src/routes/executions.ts(3,37): error TS2307: Cannot find module '@relaycron/types' or its corresponding type declarations.
17+
packages/server/src/routes/schedules.ts(8,8): error TS2307: Cannot find module '@relaycron/types' or its corresponding type declarations.
18+
packages/server/src/routes/schedules.ts(30,21): error TS7006: Parameter 'i' implicitly has an 'any' type.
19+
packages/server/src/routes/schedules.ts(247,21): error TS7006: Parameter 'i' implicitly has an 'any' type.
20+
packages/server/src/routes/ws.ts(5,15): error TS2305: Module '"../types.js"' has no exported member 'Env'.
21+
packages/server/src/routes/ws.ts(6,32): error TS2307: Cannot find module '@relaycron/types' or its corresponding type declarations.
22+
BUILD_WARNINGS
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALL_CLEAN
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WORKER_DELETED
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
**Created 2 files:**
2+
3+
**`packages/server/src/app.ts`** — App factory that cloud/standalone can both import:
4+
- `createApp(db, scheduler)` returns a configured Hono instance
5+
- Applies CORS and DB middleware globally
6+
- Mounts `/health`, `/v1/auth`, `/v1/schedules`, `/v1` (executions) routes
7+
- Includes 404 and global error handlers
8+
- Re-exports `Database` and `Scheduler` types for consumers
9+
10+
**`packages/server/src/server.ts`** — Standalone Node.js entry point:
11+
- Creates SQLite database via `createDatabase()`
12+
- Instantiates `LocalScheduler` and restores existing alarms
13+
- Serves on `PORT` env var or 4007 via `@hono/node-server`
14+
- Graceful shutdown on SIGINT/SIGTERM calls `scheduler.cancelAll()`
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Summary
2+
3+
Created `packages/server/src/db/sqlite.ts` with the following:
4+
5+
- **Imports**: `better-sqlite3`, `drizzle-orm/better-sqlite3`, schema, `mkdirSync`, `dirname`
6+
- **`createDatabase(dbPath?)`** function that:
7+
- Defaults to `process.env.RELAYCRON_DB_PATH` or `.relaycron/relaycron.db`
8+
- Creates parent directory with `mkdirSync(..., { recursive: true })`
9+
- Opens better-sqlite3 with WAL mode and foreign keys ON
10+
- Creates all 3 tables with `CREATE TABLE IF NOT EXISTS`:
11+
- **api_keys**: id, name, key_hash, key_prefix, created_at, last_used_at
12+
- **schedules**: all 18 columns matching schema.ts, with CHECK constraints for enums, CASCADE foreign key to api_keys, plus 3 indices (api_key_id, status, next_run_at)
13+
- **executions**: all 10 columns matching schema.ts, with CHECK constraints for enums, CASCADE foreign key to schedules, plus 2 indices (schedule_id, started_at)
14+
- Returns `drizzle(sqlite, { schema })`
15+
16+
No existing files were modified.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Summary
2+
3+
**Created:** `packages/server/src/engine/scheduler.ts`
4+
5+
The `LocalScheduler` class implements the `Scheduler` interface from `types.ts` and replaces Durable Object alarms with Node.js `setTimeout` timers:
6+
7+
- **`setAlarm(scheduleId, runAt)`** — Cancels any existing timer, calculates delay from `runAt`, and sets a `setTimeout`. Overdue alarms fire immediately (`delay <= 0 → setTimeout(cb, 0)`).
8+
- **`cancelAlarm(scheduleId)`** — Clears the timer and removes it from the map.
9+
- **`cancelAll()`** — Clears all active timers.
10+
- **`executeSchedule(scheduleId)`** (private) — Fetches the schedule from DB, checks it's active, executes webhook with retry (3 attempts, 1s initial backoff, 5x multiplier) or records a failure for websocket transport, then calls `advanceSchedule` and re-arms if there's a next run.
11+
- **`restoreAlarms()`** — Queries all active schedules with a `next_run_at` and sets alarms for each. Logs the count.
12+
13+
**No changes needed to `executor.ts`** — it already imports `Database` from `"../types.js"`.
14+
15+
**Type-checked:** No new TypeScript errors introduced. Used `ReturnType<typeof setTimeout>` instead of `NodeJS.Timeout` to avoid a dependency on `@types/node`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CF_FILES_REMOVED
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RENAME_DONE
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Summary
2+
3+
Rewrote both middleware files to remove Cloudflare dependencies:
4+
5+
**`packages/server/src/middleware/db.ts`**:
6+
- Removed `drizzle-orm/d1` import and `Env` Bindings type
7+
- Replaced singleton `dbMiddleware` with `createDbMiddleware(db: Database)` factory that accepts an already-constructed `Database` instance and sets it on the Hono context
8+
9+
**`packages/server/src/middleware/auth.ts`**:
10+
- Replaced `crypto.subtle.digest` (Web Crypto / CF Workers API) with `node:crypto`'s `createHash`
11+
- `hashKey` is now synchronous: `createHash("sha256").update(key).digest("hex")`
12+
- Removed `Bindings: Env` type parameter from `createMiddleware`
13+
- Replaced `c.executionCtx.waitUntil(...)` with `.then(() => {}).catch(() => {})` fire-and-forget pattern for the `last_used_at` update
14+
- `hashKey` is a named export (no longer wrapped in `async`)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Summary
2+
3+
**Two files rewritten successfully:**
4+
5+
### `packages/server/package.json`
6+
- **Added**: `main` (dist/app.js), `types` (dist/app.d.ts), `exports` map (`.`, `./scheduler`, `./db`)
7+
- **Scripts**: `start``tsx src/server.ts`, `dev``tsx watch src/server.ts`, `build``tsc`
8+
- **New deps**: `@hono/node-server ^1.13.0`, `better-sqlite3 ^11.0.0`
9+
- **New devDeps**: `@types/better-sqlite3 ^7.6.0`, `tsx ^4.0.0`
10+
- **Removed**: `wrangler`, `@cloudflare/workers-types`, `drizzle-kit`, all deploy scripts
11+
12+
### `packages/server/src/types.ts`
13+
- **Changed**: `DrizzleD1Database``BetterSQLite3Database` (from `drizzle-orm/better-sqlite3`)
14+
- **Removed**: `Env` interface (D1Database, DurableObjectNamespace references)
15+
- **Added**: `Scheduler` interface with `setAlarm(id, runAt)` and `cancelAlarm(id)` methods
16+
- **Kept**: `Database` type alias, `AuthContext` interface, Hono `ContextVariableMap` augmentation

0 commit comments

Comments
 (0)