Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions migrations/20260128113327_add_retry_logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function up(knex: Knex): Promise<void> {
`ALTER TABLE tasks ADD COLUMN retry_count INTEGER NOT NULL DEFAULT 0;`,
);
await knex.raw(
`ALTER TABLE tasks ADD COLUMN max_retries INTEGER NOT NULL DEFAULT 3;`,
`ALTER TABLE tasks ADD COLUMN max_attempts INTEGER NOT NULL DEFAULT 3;`,
);
await knex.raw(`ALTER TABLE tasks ADD COLUMN error_message TEXT;`);

Expand All @@ -15,7 +15,7 @@ export async function up(knex: Knex): Promise<void> {

export async function down(knex: Knex): Promise<void> {
await knex.raw(`ALTER TABLE tasks DROP COLUMN retry_count;`);
await knex.raw(`ALTER TABLE tasks DROP COLUMN max_retries;`);
await knex.raw(`ALTER TABLE tasks DROP COLUMN max_attempts;`);
await knex.raw(`ALTER TABLE tasks DROP COLUMN error_message;`);

// Note: PostgreSQL does not support simply removing values from enums.
Expand Down
8 changes: 4 additions & 4 deletions src/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ while (true) {
} catch (error) {
const newRetryCount = task.retry_count + 1;

if (newRetryCount >= task.max_retries) {
// Max retries exceeded, mark as failed
if (newRetryCount >= task.max_attempts) {
// Max attempts exceeded, mark as failed
await db('tasks')
.update({
status: 'failed',
Expand All @@ -42,7 +42,7 @@ while (true) {
.where({ id: task.id });

console.log(
`❌ Task failed permanently after ${newRetryCount} retries:`,
`❌ Task failed permanently (${newRetryCount} failures):`,
task.id,
);
} else {
Expand All @@ -56,7 +56,7 @@ while (true) {
.where({ id: task.id });

console.log(
`🔄 Task failed, retry ${newRetryCount}/${task.max_retries}:`,
`🔄 Task failed (failure ${newRetryCount}/${task.max_attempts}):`,
task.id,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type Task = {
payload: Payload;
status: 'pending' | 'in_progress' | 'done' | 'failed';
retry_count: number;
max_retries: number;
max_attempts: number;
error_message: string | null;
created_at: string;
picked_at: string | null;
Expand Down