Skip to content

Commit 95ef237

Browse files
committed
chore: wip
chore: wip chore: wip
1 parent e11b8c9 commit 95ef237

File tree

6 files changed

+52
-13
lines changed

6 files changed

+52
-13
lines changed

bun.lock

+3-7
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,6 @@
11351135
"storage/framework/core/queue": {
11361136
"name": "@stacksjs/queue",
11371137
"version": "0.68.2",
1138-
"dependencies": {
1139-
"@poppinss/defer": "^1.1.0",
1140-
},
11411138
"devDependencies": {
11421139
"@stacksjs/development": "storage/framework/core/development",
11431140
},
@@ -1205,6 +1202,7 @@
12051202
"croner": "^9.0.0",
12061203
},
12071204
"devDependencies": {
1205+
"@stacksjs/actions": "storage/framework/core/actions",
12081206
"@stacksjs/development": "storage/framework/core/development",
12091207
},
12101208
},
@@ -2388,8 +2386,6 @@
23882386

23892387
"@polka/url": ["@polka/[email protected]", "", {}, "sha512-8LduaNlMZGwdZ6qWrKlfa+2M4gahzFkprZiAt2TF8uS0qQgBizKXpXURqvTJ4WtmupWxaLqjRb2UCTe72mu+Aw=="],
23902388

2391-
"@poppinss/defer": ["@poppinss/[email protected]", "", { "dependencies": { "fastq": "^1.17.1" } }, "sha512-+hkwxhKdxbmfTNo9MJrY2Rz7GrMokgx71zSSnEv6/pftaCQ8+bF5vQkE7KCBIKUn+kCth1cI1d8LWDMvPUIRMw=="],
2392-
23932389
"@poppinss/macroable": ["@poppinss/[email protected]", "", {}, "sha512-B4iV6QxW//Fn17+qF1EMZRmoThIUJlCtcO85yoRDJnMyHeAthjz4ig9OTkfGGXKtQhcdPX0me75gU5K9J897+w=="],
23942390

23952391
"@poppinss/utils": ["@poppinss/[email protected]", "", { "dependencies": { "@lukeed/ms": "^2.0.2", "@types/bytes": "^3.1.4", "@types/pluralize": "^0.0.33", "bytes": "^3.1.2", "case-anything": "^3.1.0", "flattie": "^1.1.1", "pluralize": "^8.0.0", "safe-stable-stringify": "^2.5.0", "secure-json-parse": "^2.7.0", "slash": "^5.1.0", "slugify": "^1.6.6", "truncatise": "^0.0.8" } }, "sha512-YGeH7pIUm9ExONURNH3xN61dBZ0SXgVuPA9E76t7EHeZHXPNrmR8TlbXQaka6kd5n+cpBNcHG4VsVfYf59bZ7g=="],
@@ -2712,7 +2708,7 @@
27122708

27132709
"@stacksjs/query-builder": ["@stacksjs/query-builder@workspace:storage/framework/core/query-builder", { "dependencies": { "@stacksjs/database": "storage/framework/core/database", "@stacksjs/types": "storage/framework/core/types", "kysely": "^0.27.5", "kysely-bun-worker": "^0.7.0", "mysql2": "^3.12.0", "pg": "^8.13.1" }, "devDependencies": { "@stacksjs/development": "storage/framework/core/development", "@types/pg": "^8.11.10" } }],
27142710

2715-
"@stacksjs/queue": ["@stacksjs/queue@workspace:storage/framework/core/queue", { "dependencies": { "@poppinss/defer": "^1.1.0" }, "devDependencies": { "@stacksjs/development": "storage/framework/core/development" } }],
2711+
"@stacksjs/queue": ["@stacksjs/queue@workspace:storage/framework/core/queue", { "devDependencies": { "@stacksjs/development": "storage/framework/core/development" } }],
27162712

27172713
"@stacksjs/radio-group": ["@stacksjs/radio-group@workspace:storage/framework/core/components/radio-group", { "dependencies": { "@stacksjs/ui": "storage/framework/core/ui", "highlight.js": "^11.11.1" }, "devDependencies": { "@iconify-json/heroicons": "^1.2.2", "@microsoft/api-extractor": "^7.48.1", "@stacksjs/alias": "storage/framework/core/alias", "@stacksjs/development": "storage/framework/core/development", "@types/clean-css": "^4.2.11", "@vue/tsconfig": "^0.7.0", "clean-css": "^5.3.3", "unocss": "0.65.3", "unplugin-icons": "^0.22.0" } }],
27182714

@@ -2726,7 +2722,7 @@
27262722

27272723
"@stacksjs/rpx": ["@stacksjs/[email protected]", "", { "bin": { "rpx": "dist/bin/cli.js", "reverse-proxy": "dist/bin/cli.js" } }, "sha512-Lus+Zvn4+0g7InjTtsIC6pZ4lR4sYY/oB4OrBDNNfIedEQOYLgSZoj3lynZlv6A3UJQzDtzZfFMMGoQfTgxXFw=="],
27282724

2729-
"@stacksjs/scheduler": ["@stacksjs/scheduler@workspace:storage/framework/core/scheduler", { "dependencies": { "croner": "^9.0.0" }, "devDependencies": { "@stacksjs/development": "storage/framework/core/development" } }],
2725+
"@stacksjs/scheduler": ["@stacksjs/scheduler@workspace:storage/framework/core/scheduler", { "dependencies": { "croner": "^9.0.0" }, "devDependencies": { "@stacksjs/actions": "storage/framework/core/actions", "@stacksjs/development": "storage/framework/core/development" } }],
27302726

27312727
"@stacksjs/search-engine": ["@stacksjs/search-engine@workspace:storage/framework/core/search-engine", { "dependencies": { "@opensearch-project/opensearch": "^2.13.0", "meilisearch": "^0.47.0" }, "devDependencies": { "@stacksjs/config": "storage/framework/core/config", "@stacksjs/development": "storage/framework/core/development" } }],
27322728

storage/framework/core/queue/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
"typecheck": "bun tsc --noEmit",
4343
"prepublishOnly": "bun run build"
4444
},
45-
"dependencies": {
46-
"@poppinss/defer": "^1.1.0"
47-
},
4845
"devDependencies": {
4946
"@stacksjs/development": "workspace:*"
5047
}

storage/framework/core/queue/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ export class Job {
2222
}
2323
}
2424

25-
export { DeferQueue } from '@poppinss/defer'
25+
export { runJob } from './run'
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { runAction } from '@stacksjs/actions'
2+
import { log } from '@stacksjs/cli'
3+
import { projectPath } from '@stacksjs/path'
4+
5+
interface JobConfig {
6+
name?: string
7+
description?: string
8+
tries?: number
9+
backoff?: number
10+
rate?: string
11+
handle?: () => void | Promise<void>
12+
action?: string | (() => void | Promise<void>)
13+
}
14+
15+
export async function runJob(name: string): Promise<void> {
16+
log.info(`Running job: ${name}`)
17+
try {
18+
const jobModule = await import(projectPath(`Jobs/${name}.ts`))
19+
const job = jobModule.default as JobConfig
20+
21+
if (job.action) {
22+
// If action is a string, run it via runAction
23+
if (typeof job.action === 'string') {
24+
await runAction(job.action)
25+
}
26+
// If action is a function, execute it directly
27+
else if (typeof job.action === 'function') {
28+
await job.action()
29+
}
30+
}
31+
// If handle is defined, execute it
32+
else if (job.handle) {
33+
await job.handle()
34+
}
35+
else {
36+
throw new Error(`Job ${name} must define either a handle function or an action`)
37+
}
38+
}
39+
catch (error) {
40+
log.error(`Job ${name} failed:`, error)
41+
throw error
42+
}
43+
}

storage/framework/core/scheduler/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"croner": "^9.0.0"
3838
},
3939
"devDependencies": {
40+
"@stacksjs/actions": "workspace:*",
4041
"@stacksjs/development": "workspace:*"
4142
}
4243
}

storage/framework/core/scheduler/src/schedule.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { CatchCallbackFn, CronOptions } from './'
22
import type { Timezone } from './types'
3+
import { runAction } from '@stacksjs/actions'
34
import { log, runCommand } from '@stacksjs/cli'
5+
import { runJob } from '@stacksjs/queue'
46
import { Cron } from './'
57

68
// Base interface for common methods
@@ -212,7 +214,7 @@ export class Schedule implements UntimedSchedule {
212214
return new Schedule(async () => {
213215
log.info(`Running job: ${name}`)
214216
try {
215-
await runCommand(`node path/to/jobs/${name}.js`)
217+
await runJob(name)
216218
}
217219
catch (error) {
218220
log.error(`Job ${name} failed:`, error)
@@ -225,7 +227,7 @@ export class Schedule implements UntimedSchedule {
225227
return new Schedule(async () => {
226228
log.info(`Running action: ${name}`)
227229
try {
228-
await runCommand(`node path/to/actions/${name}.js`)
230+
await runAction(name)
229231
}
230232
catch (error) {
231233
log.error(`Action ${name} failed:`, error)

0 commit comments

Comments
 (0)