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 1ef7a17 commit b95acb3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
10 changes: 9 additions & 1 deletion storage/framework/core/orm/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ export async function generateModelString(

jsonFields += '\nid: this.id,\n'
for (const attribute of attributes) {
const entity = attribute.fieldArray?.entity === 'enum' ? 'string[]' : attribute.fieldArray?.entity
const entity = mapEntity(attribute)

fieldString += ` ${snakeCase(attribute.field)}?: ${entity}\n `
declareFields += `public ${snakeCase(attribute.field)}: ${entity} | undefined \n `
Expand Down Expand Up @@ -2447,6 +2447,14 @@ export async function generateModelString(
`
}

function mapEntity(attribute: ModelElement): string | undefined {
const entity = attribute.fieldArray?.entity === 'enum' ? 'string[]' : attribute.fieldArray?.entity

const mapEntity = entity === 'date' ? 'Date' : entity

return mapEntity
}

export async function generateModelFiles(modelStringFile?: string): Promise<void> {
try {
log.info('Cleanup of older Models...')
Expand Down
11 changes: 4 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 @@ -20,12 +20,9 @@ export async function processJobs(queue: string | undefined): Promise<Ok<string,
}

async function executeJobs(queue: string | undefined): Promise<void> {
let jobs: JobModel[]

if (queue)
jobs = await Job.whereQueue(queue).get()
else
jobs = await Job.all()
const jobs = await Job.when(queue !== undefined, (query: any) => {
return query.where('queue', queue)
}).get()

for (const job of jobs) {
if (job.payload) {
Expand Down
6 changes: 3 additions & 3 deletions storage/framework/orm/src/models/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface JobsTable {
payload?: string
attempts?: number
available_at?: number
reserved_at?: date
reserved_at?: Date

created_at?: Date

Expand Down Expand Up @@ -59,7 +59,7 @@ export class JobModel {
public payload: string | undefined
public attempts: number | undefined
public available_at: number | undefined
public reserved_at: date | undefined
public reserved_at: Date | undefined

public created_at: Date | undefined
public updated_at: Date | undefined
Expand Down Expand Up @@ -840,7 +840,7 @@ export async function whereAvailableAt(value: number): Promise<JobModel[]> {
return results.map(modelItem => new JobModel(modelItem))
}

export async function whereReservedAt(value: date): Promise<JobModel[]> {
export async function whereReservedAt(value: Date): Promise<JobModel[]> {
const query = db.selectFrom('jobs').where('reserved_at', '=', value)
const results = await query.execute()

Expand Down

0 comments on commit b95acb3

Please sign in to comment.