create-wervt 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-wervt",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Create a new wervt app: Nuxt 5, Postgres with Drizzle, live data with Electric.",
5
5
  "homepage": "https://wervt.app",
6
6
  "license": "MIT",
@@ -99,15 +99,50 @@ const { data: todos, isLive } = await useShape<Todo>('/api/shapes/todos')
99
99
  - For your own state (anonymous visitors too), use `useSession(event, { name })` from
100
100
  `nuxt/server`. The secret is set by wervt.
101
101
 
102
+ ## Tasks (cron)
103
+
104
+ Periodic work (cleanup, syncs, renewals) goes into tasks, not into requests:
105
+
106
+ ```ts
107
+ // server/tasks/presence/sweep.ts → task "presence:sweep"
108
+ import { defineTask, useDb } from '@wervt/nuxt/server'
109
+ import { lt } from 'drizzle-orm'
110
+ import { presence } from '../../db/schema'
111
+
112
+ export default defineTask({
113
+ meta: { description: 'Remove presence older than 5 minutes' },
114
+ async run() {
115
+ await useDb()
116
+ .delete(presence)
117
+ .where(lt(presence.seenAt, new Date(Date.now() - 5 * 60_000)))
118
+ return { result: 'ok' }
119
+ },
120
+ })
121
+ ```
122
+
123
+ ```ts
124
+ // nuxt.config.ts
125
+ nitro: { scheduledTasks: { '*/5 * * * *': ['presence:sweep'] } },
126
+ wervt: { timezone: 'Europe/Berlin' }, // optional, UTC by default
127
+ ```
128
+
129
+ - wervt runs scheduled tasks; `nuxt dev` runs them locally. Import `defineTask` from
130
+ `@wervt/nuxt/server`.
131
+ - A run has the limits of a request (5 minutes, limited CPU). Keep tasks short and idempotent:
132
+ a run that's still going when the next one is due is skipped, and runs missed while wervt was
133
+ down aren't caught up.
134
+ - At most once a minute. Tasks without a schedule can still be run by hand (dashboard or
135
+ `pnpm exec wervt tasks <app> --run <name>`), e.g. for a backfill.
136
+ - Every run is logged: `pnpm exec wervt logs <app> 'type:=Task'`.
137
+
102
138
  ## Don'ts
103
139
 
104
140
  - No Node-only APIs that Deno lacks (`child_process`, native addons, writing to the filesystem).
105
141
  Store data in Postgres.
106
142
  - No long-running work in requests (CPU is limited per request) and no in-memory state that must
107
143
  survive: isolates are started and stopped on demand.
108
- - No WebSockets, SSE hubs or timers that push to clients. Write to the database and let clients
109
- read live data through shapes. No background jobs or cron either: do periodic cleanup lazily in
110
- requests.
144
+ - No WebSockets, SSE hubs or timers (`setInterval`) that push to clients. Write to the database
145
+ and let clients read live data through shapes. For periodic work, use a task (above).
111
146
  - No secrets in client code. Server env vars come from wervt; don't hardcode credentials.
112
147
 
113
148
  ## Logs
@@ -9,13 +9,13 @@
9
9
  "postinstall": "nuxt prepare"
10
10
  },
11
11
  "dependencies": {
12
- "@wervt/nuxt": "^0.2.1",
12
+ "@wervt/nuxt": "^0.2.2",
13
13
  "drizzle-orm": "1.0.0-rc.4",
14
14
  "nuxt": "npm:nuxt-nightly@5x",
15
15
  "valibot": "^1.5.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@wervt/cli": "^0.2.1",
18
+ "@wervt/cli": "^0.2.4",
19
19
  "drizzle-kit": "1.0.0-rc.4",
20
20
  "vite-plus": "^1.0.0"
21
21
  }