Skip to content

Commit

Permalink
Merge pull request #11 from spikeninja/dev
Browse files Browse the repository at this point in the history
feat: 1.2.0 version
  • Loading branch information
spikeninja authored Dec 11, 2024
2 parents 42f26f3 + 2ad7845 commit 378e6bb
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 52 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nuxt-app",
"private": true,
"type": "module",
"version": "1.1.3",
"version": "1.2.0",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
Expand All @@ -13,15 +13,15 @@
},
"dependencies": {
"@vueuse/core": "^12.0.0",
"better-sqlite3": "^11.6.0",
"better-sqlite3": "^11.7.0",
"bootstrap": "^5.3.3",
"dayjs": "^1.11.13",
"drizzle-kit": "^0.29.1",
"drizzle-orm": "^0.37.0",
"drizzle-kit": "^0.30.0",
"drizzle-orm": "^0.38.0",
"nuxt": "^3.14.1592",
"vue": "^3.5.13",
"vue-router": "^4.5.0",
"zod": "^3.23.8"
"zod": "^3.24.1"
},
"packageManager": "[email protected]+sha1.a428b12202bc4f23b17e6dffe730734dae5728e2",
"devDependencies": {
Expand Down
58 changes: 29 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/pages/tasks/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const { data: task, error } = useFetch(`/api/tasks/${route.params.id}`)
:class="{
'bg-success': task.state === 'success',
'bg-danger': task.state === 'failure',
'bg-warning': task.state === 'pending',
'bg-warning': task.state === 'running',
'bg-dark': task.state === 'abandoned',
}"
>
{{ task.state }}
Expand Down
15 changes: 9 additions & 6 deletions src/pages/tasks/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const state = computed(() => route.query.state)
const search = computed(() => route.query.search || "")
const page = computed(() => Number(route.query.page) || 1)
const { data, refresh } = useAsyncData(
const { data, refresh } = useAsyncData<{ tasks: TaskSelect[]; count: number }>(
"tasks",
() =>
$fetch(`/api/tasks`, {
Expand Down Expand Up @@ -65,7 +65,9 @@ const formatTaskName = (taskName: string) => {
}
}
const stateHandler = (state: "pending" | "success" | "failure") => {
const stateHandler = (
state: "running" | "success" | "failure" | "abandoned"
) => {
router.push({
path: "/tasks",
query: {
Expand Down Expand Up @@ -172,18 +174,19 @@ const handlePrev = () => {
:class="{
'bg-success': task.state === 'success',
'bg-danger': task.state === 'failure',
'bg-warning': task.state === 'pending',
'bg-warning': task.state === 'running',
'bg-dark': task.state === 'abandoned',
}"
>
{{ task.state }}
</span>
</td>
<td>{{ task.args }}</td>
<td>{{ limitText(JSON.stringify(task.kwargs), 40) }}</td>
<td>{{ formatReturnValue(task) }}</td>
<td>{{ formatDate(task.startedAt) }}</td>
<td>{{ limitText(formatReturnValue(task), 21) }}</td>
<td>{{ formatDate(String(task.startedAt)) }}</td>
<td>
{{ task.finishedAt ? formatDate(task.finishedAt) : null }}
{{ task.finishedAt ? formatDate(String(task.finishedAt)) : null }}
</td>
<td>{{ task.executionTime }}</td>
<td>{{ task.worker }}</td>
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/tasks/[id]/started.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineEventHandler(async (event) => {
finishedAt: null,
returnValue: null,
executionTime: null,
state: "pending",
state: "running",
args: body.args,
id: params.id,
worker: body.worker,
Expand Down
6 changes: 5 additions & 1 deletion src/server/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const tasksTable = sqliteTable(
{
id: text().primaryKey(),
name: text().notNull(),
state: text({ enum: ["success", "pending", "failure"] }).notNull(),
state: text({
enum: ["success", "running", "failure", "abandoned"],
}).notNull(),
error: text(),
worker: text(),
executionTime: real("execution_time"),
Expand All @@ -19,8 +21,10 @@ export const tasksTable = sqliteTable(
}>(),
},
(t) => ({
idxState: index("idx_tasks__state").on(t.state),
idxStartedAt: index("idx_tasks__started_at").on(t.startedAt),
idxFinishedAt: index("idx_tasks__finished_at").on(t.finishedAt),
idxExecutionTime: index("idx_tasks__execution_time").on(t.executionTime),
})
)

Expand Down
7 changes: 7 additions & 0 deletions src/server/plugins/shutdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { tasksRepository } from "~/server/repositories/tasks"

export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook("close", async () => {
await tasksRepository.setAbandoned()
})
})
23 changes: 15 additions & 8 deletions src/server/repositories/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tasksTable } from "../db/schema"
import { takeUniqueOrThrow } from "../utils"
import { count, eq, desc, like, and } from "drizzle-orm"

export type TaskState = "pending" | "success" | "failed"
export type TaskState = "running" | "success" | "failed" | "abandoned"

class TasksRepository {
async getAll({
Expand All @@ -15,7 +15,7 @@ class TasksRepository {
limit: number
offset: number
name: string | null
state?: "success" | "pending" | "failure"
state?: "success" | "running" | "failure" | "abandoned"
}) {
const whereCondition = name
? like(tasksTable.name, `%${name.toLowerCase()}%`)
Expand Down Expand Up @@ -57,28 +57,35 @@ class TasksRepository {
name: string
worker: string
startedAt: Date
args: Record<string, any>
args: Array<any>
finishedAt: Date | null
kwargs: Record<string, any>
executionTime: number | null
returnValue: Record<string, any> | null
finishedAt: Date | null
state: "success" | "pending" | "failure"
returnValue: { return_value: any } | null
state: "success" | "running" | "failure"
}) {
return db.insert(tasksTable).values(values)
}

async update(
taskId: string,
values: {
state?: "success" | "pending" | "failure"
error?: string | null
executionTime?: number
finishedAt?: Date | null
returnValue?: object | null
returnValue?: { return_value: any } | null
state?: "success" | "running" | "failure" | "abandoned"
}
) {
return db.update(tasksTable).set(values).where(eq(tasksTable.id, taskId))
}

async setAbandoned() {
return db
.update(tasksTable)
.set({ state: "abandoned" })
.where(eq(tasksTable.state, "running"))
}
}

export const tasksRepository = new TasksRepository()
2 changes: 1 addition & 1 deletion src/server/schemas/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export const getTasksQueryParamsSchema = z.object({
search: z.string().optional(),
limit: z.coerce.number().gte(0),
offset: z.coerce.number().gte(0),
state: z.enum(["success", "pending", "failure"]).optional(),
state: z.enum(["success", "running", "failure", "abandoned"]).optional(),
})

0 comments on commit 378e6bb

Please sign in to comment.