Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmichael123 committed Jan 8, 2025
1 parent 5163625 commit 9a71fa6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions storage/framework/core/buddy/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ async function main() {
cmd.make(buddy)
cmd.migrate(buddy)
cmd.outdated(buddy)
cmd.queue(buddy)
cmd.release(buddy)
cmd.route(buddy)
cmd.saas(buddy)
Expand Down
2 changes: 0 additions & 2 deletions storage/framework/core/queue/src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export interface JobOptions {
}

export async function runJob(name: string, options: JobOptions = {}): Promise<void> {
log.info(`Running job: ${name}`)

try {
const jobModule = await import(appPath(`Jobs/${name}.ts`))
const job = jobModule.default as JobConfig
Expand Down
37 changes: 34 additions & 3 deletions storage/framework/core/queue/src/process.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
import { Job } from "../../../orm/src/models/Job";
import { log } from '@stacksjs/logging'
import { Job } from "../../../orm/src/models/Job"
import { runJob } from "./job"

interface QueuePayload {
displayName: string,
name: string,
maxTries: number,
timeOut: number | null,
timeOutAt: Date | null
}

export async function processJobs(): Promise<void> {
const jobs = await Job.all()

for (const job of jobs) {
console.log(job)
if (job.payload) {
const payload: QueuePayload = JSON.parse(job.payload)
const currentAttempts = job.attempts || 0
log.info(`Running ${payload.displayName}`)

job.update({attempts: currentAttempts + 1 })

try {
await runJob(payload.name, {
queue: job.queue,
payload: {},
context: '',
maxTries: payload.maxTries,
timeout: 60,
})
} catch (error) {
log.info(`${payload.displayName} failed`)
log.error(error)
}

log.info(`Successfully ran ${payload.displayName}`)
}
}
}
}
2 changes: 1 addition & 1 deletion storage/framework/core/queue/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { JobOptions } from "./job"
import process from 'node:process'
import Job from "../../../orm/src/models/Job"

export async function storeJob(name: string, options: JobOptions): Promise<void> {
const payloadJson = JSON.stringify({
displayName: `app/Jobs/${name}.ts`,
name,
maxTries: options.tries || 1,
timeout: null,
timeoutAt: null
Expand Down

0 comments on commit 9a71fa6

Please sign in to comment.