Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
chore: wip

chore: wip
  • Loading branch information
chrisbbreuer committed Dec 28, 2024
1 parent e11b8c9 commit 95ef237
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
10 changes: 3 additions & 7 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,6 @@
"storage/framework/core/queue": {
"name": "@stacksjs/queue",
"version": "0.68.2",
"dependencies": {
"@poppinss/defer": "^1.1.0",
},
"devDependencies": {
"@stacksjs/development": "storage/framework/core/development",
},
Expand Down Expand Up @@ -1205,6 +1202,7 @@
"croner": "^9.0.0",
},
"devDependencies": {
"@stacksjs/actions": "storage/framework/core/actions",
"@stacksjs/development": "storage/framework/core/development",
},
},
Expand Down Expand Up @@ -2388,8 +2386,6 @@

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

"@poppinss/defer": ["@poppinss/[email protected]", "", { "dependencies": { "fastq": "^1.17.1" } }, "sha512-+hkwxhKdxbmfTNo9MJrY2Rz7GrMokgx71zSSnEv6/pftaCQ8+bF5vQkE7KCBIKUn+kCth1cI1d8LWDMvPUIRMw=="],

"@poppinss/macroable": ["@poppinss/[email protected]", "", {}, "sha512-B4iV6QxW//Fn17+qF1EMZRmoThIUJlCtcO85yoRDJnMyHeAthjz4ig9OTkfGGXKtQhcdPX0me75gU5K9J897+w=="],

"@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=="],
Expand Down Expand Up @@ -2712,7 +2708,7 @@

"@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" } }],

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

"@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" } }],

Expand All @@ -2726,7 +2722,7 @@

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

"@stacksjs/scheduler": ["@stacksjs/scheduler@workspace:storage/framework/core/scheduler", { "dependencies": { "croner": "^9.0.0" }, "devDependencies": { "@stacksjs/development": "storage/framework/core/development" } }],
"@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" } }],

"@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" } }],

Expand Down
3 changes: 0 additions & 3 deletions storage/framework/core/queue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
"typecheck": "bun tsc --noEmit",
"prepublishOnly": "bun run build"
},
"dependencies": {
"@poppinss/defer": "^1.1.0"
},
"devDependencies": {
"@stacksjs/development": "workspace:*"
}
Expand Down
2 changes: 1 addition & 1 deletion storage/framework/core/queue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export class Job {
}
}

export { DeferQueue } from '@poppinss/defer'
export { runJob } from './run'
43 changes: 43 additions & 0 deletions storage/framework/core/queue/src/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { runAction } from '@stacksjs/actions'
import { log } from '@stacksjs/cli'
import { projectPath } from '@stacksjs/path'

interface JobConfig {
name?: string
description?: string
tries?: number
backoff?: number
rate?: string
handle?: () => void | Promise<void>
action?: string | (() => void | Promise<void>)
}

export async function runJob(name: string): Promise<void> {
log.info(`Running job: ${name}`)
try {
const jobModule = await import(projectPath(`Jobs/${name}.ts`))
const job = jobModule.default as JobConfig

if (job.action) {
// If action is a string, run it via runAction
if (typeof job.action === 'string') {
await runAction(job.action)
}
// If action is a function, execute it directly
else if (typeof job.action === 'function') {
await job.action()
}
}
// If handle is defined, execute it
else if (job.handle) {
await job.handle()
}
else {
throw new Error(`Job ${name} must define either a handle function or an action`)
}
}
catch (error) {
log.error(`Job ${name} failed:`, error)
throw error
}
}
1 change: 1 addition & 0 deletions storage/framework/core/scheduler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"croner": "^9.0.0"
},
"devDependencies": {
"@stacksjs/actions": "workspace:*",
"@stacksjs/development": "workspace:*"
}
}
6 changes: 4 additions & 2 deletions storage/framework/core/scheduler/src/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { CatchCallbackFn, CronOptions } from './'
import type { Timezone } from './types'
import { runAction } from '@stacksjs/actions'
import { log, runCommand } from '@stacksjs/cli'
import { runJob } from '@stacksjs/queue'
import { Cron } from './'

// Base interface for common methods
Expand Down Expand Up @@ -212,7 +214,7 @@ export class Schedule implements UntimedSchedule {
return new Schedule(async () => {
log.info(`Running job: ${name}`)
try {
await runCommand(`node path/to/jobs/${name}.js`)
await runJob(name)
}
catch (error) {
log.error(`Job ${name} failed:`, error)
Expand All @@ -225,7 +227,7 @@ export class Schedule implements UntimedSchedule {
return new Schedule(async () => {
log.info(`Running action: ${name}`)
try {
await runCommand(`node path/to/actions/${name}.js`)
await runAction(name)
}
catch (error) {
log.error(`Action ${name} failed:`, error)
Expand Down

0 comments on commit 95ef237

Please sign in to comment.