Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmichael123 committed Jan 9, 2025
1 parent 5671651 commit b2175cd
Show file tree
Hide file tree
Showing 9 changed files with 938 additions and 13 deletions.
18 changes: 11 additions & 7 deletions storage/framework/core/queue/src/process.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ok, type Ok } from '@stacksjs/error-handling'
import { log } from '@stacksjs/logging'
import { Job, type JobModel } from '../../../orm/src/models/Job'
import { Job } from '../../../orm/src/models/Job'
import { runJob } from './job'

interface QueuePayload {
Expand All @@ -16,7 +16,8 @@ export async function processJobs(queue: string | undefined): Promise<Ok<string,
async function process() {
try {
await executeJobs(queue)
} catch (error) {
}
catch (error) {
log.error('Error processing jobs:', error)
}

Expand All @@ -32,10 +33,11 @@ async function executeJobs(queue: string | undefined): Promise<void> {
const jobs = await Job.when(queue !== undefined, (query: any) => query.where('queue', queue)).get()

for (const job of jobs) {
if (!job.payload)
continue

if (!job.payload) continue

if (job.available_at && job.available_at > timestampNow()) continue
if (job.available_at && job.available_at > timestampNow())
continue

const body: QueuePayload = JSON.parse(job.payload)
const currentAttempts = job.attempts || 0
Expand All @@ -55,7 +57,8 @@ async function executeJobs(queue: string | undefined): Promise<void> {

await job.delete()
log.info(`Successfully ran job: ${body.displayName}`)
} catch (error) {
}
catch (error) {
log.error(`Job failed: ${body.displayName}`, error)
}
}
Expand All @@ -64,7 +67,8 @@ async function executeJobs(queue: string | undefined): Promise<void> {
async function updateJobAttempts(job: any, currentAttempts: number): Promise<void> {
try {
await job.update({ attempts: currentAttempts + 1 })
} catch (error) {
}
catch (error) {
log.error('Failed to update job attempts:', error)
}
}
Expand Down
2 changes: 1 addition & 1 deletion storage/framework/core/queue/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function storeJob(name: string, options: QueueOption): Promise<void
maxTries: options.tries || 1,
timeout: null,
timeoutAt: null,
payload: options.payload || {}
payload: options.payload || {},
})

const job = {
Expand Down
2 changes: 1 addition & 1 deletion storage/framework/core/types/src/model-names.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type ModelNames = 'Project' | 'SubscriberEmail' | 'AccessToken' | 'Team' | 'Subscriber' | 'Deployment' | 'Release' | 'User' | 'Post' | 'Product' | 'PaymentMethod' | 'Transaction' | 'Job' | 'Subscription' | 'Error'
export type ModelNames = 'Project' | 'SubscriberEmail' | 'AccessToken' | 'Team' | 'Subscriber' | 'Deployment' | 'Release' | 'User' | 'Post' | 'FailedJob' | 'Product' | 'PaymentMethod' | 'Transaction' | 'Job' | 'Subscription' | 'Error'
2 changes: 1 addition & 1 deletion storage/framework/core/types/src/table-names.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type TableNames = 'projects' | 'subscriber_emails' | 'personal_access_tokens' | 'personal_access_token_teams' | 'team_users' | 'teams' | 'subscribers' | 'deployments' | 'releases' | 'team_users' | 'users' | 'posts' | 'products' | 'payment_methods' | 'transactions' | 'jobs' | 'subscriptions' | 'errors'
export type TableNames = 'projects' | 'subscriber_emails' | 'personal_access_tokens' | 'personal_access_token_teams' | 'team_users' | 'teams' | 'subscribers' | 'deployments' | 'releases' | 'team_users' | 'users' | 'posts' | 'failed_jobs' | 'products' | 'payment_methods' | 'transactions' | 'jobs' | 'subscriptions' | 'errors'
4 changes: 2 additions & 2 deletions storage/framework/database/models/generated/FailedJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
},
factory: () => 'default',
},

queue: {
required: true,
fillable: true,
Expand Down Expand Up @@ -62,6 +62,6 @@ export default {
rule: schema.date(),
},
factory: () => '2024-12-23 13:32:19',
}
},
},
} satisfies Model
Loading

0 comments on commit b2175cd

Please sign in to comment.