Skip to content

Commit

Permalink
feat: add getJobCounts
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Oct 1, 2023
1 parent 98c52af commit d138fed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
13 changes: 7 additions & 6 deletions src/controllers/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ enum QueueCommandTypes {
Add = "add",
Pause = "pause",
Resume = "resume",
Empty = "empty",
Clean = "clean",
Count = "count",
GetJobs = "getJobs",
GetJobsCount = "getJobsCount",
GetJobCounts = "getJobCounts",
GetJobLogs = "getJobLogs",
RemoveRepeatable = "removeRepeatable",
JobsCommand = "jobs",
JobUpdate = "jobUpdate",
JobProgress = "jobProgress",
JobLog = "jobLog",
}
Expand Down Expand Up @@ -57,6 +52,11 @@ const GetJobsSchema = Type.Object({
]),
});

const GetJobCountsSchema = Type.Object({
fn: Type.Literal(QueueCommandTypes.GetJobCounts),
args: Type.Tuple([]),
});

const UpdateJobProgressSchema = Type.Object({
fn: Type.Literal(QueueCommandTypes.JobProgress),
args: Type.Tuple([Type.String(), Type.Union([Type.Number(), Type.Any()])]),
Expand All @@ -67,6 +67,7 @@ export const QueueSchema = Type.Union([
PauseSchema,
ResumeSchema,
GetJobsSchema,
GetJobCountsSchema,
UpdateJobProgressSchema,
]);

Expand Down
14 changes: 5 additions & 9 deletions src/controllers/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ export const QueueController: WebSocketBehaviour = {
const errors = Value.Errors(QueueSchema, parsedMessage.data);
const firstError = errors.First();
if (firstError) {
const errorResponse = [firstError];
for (const err of errors) {
errorResponse.push(err);
}
if (errorResponse.length > 0) {
respond(ws, parsedMessage.id, { errors: errorResponse });
return;
}
// The errors are difficult to read, so we'll just send a generic one
// until we can do something better.
respond(ws, parsedMessage.id, { err: { message: `Invalid message ${message}`, stack: "" } })
return;
}

const queue = ws.data.queue;
Expand All @@ -52,7 +48,7 @@ export const QueueController: WebSocketBehaviour = {
const result = await queue[fn].apply(queue, args);
respond(ws, parsedMessage.id, { ok: result });
} catch (err) {
respond(ws, parsedMessage.id, { error: (<Error>err).message });
respond(ws, parsedMessage.id, { err: (<Error>err).message });
}
} catch (err) {
console.error(err);
Expand Down

0 comments on commit d138fed

Please sign in to comment.