sleep 10 second between each run
This commit is contained in:
parent
0c0c836184
commit
956b0d9751
30
index.ts
30
index.ts
@ -1,41 +1,13 @@
|
||||
import amqp from "amqplib";
|
||||
import { processImage } from "./process-image";
|
||||
import dotenv from "dotenv";
|
||||
import { sleepWithCountdown } from "./util";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const queueName = process.env.QUEUE_NAME || "storage.file";
|
||||
const rabbitUrl = process.env.RABBITMQ_URL || "amqp://localhost";
|
||||
|
||||
function sleepWithCountdown(seconds: number): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
let remaining = seconds;
|
||||
|
||||
const update = () => {
|
||||
const msg = `⏳ Waiting ${remaining}s...`;
|
||||
process.stdout.clearLine(0); // Clear current line
|
||||
process.stdout.cursorTo(0); // Move cursor to start of line
|
||||
process.stdout.write(msg); // Write message
|
||||
};
|
||||
|
||||
update(); // Initial message
|
||||
|
||||
const interval = setInterval(() => {
|
||||
remaining--;
|
||||
|
||||
if (remaining > 0) {
|
||||
update();
|
||||
} else {
|
||||
clearInterval(interval);
|
||||
process.stdout.clearLine(0);
|
||||
process.stdout.cursorTo(0);
|
||||
process.stdout.write(`✅ Resuming now\n`);
|
||||
resolve();
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
async function start() {
|
||||
const conn = await amqp.connect(rabbitUrl);
|
||||
const channel = await conn.createChannel();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import sharp from "sharp";
|
||||
import { getMinioClient } from "./minio";
|
||||
import { lookup } from "mime-types";
|
||||
import { sleepWithCountdown } from "./util";
|
||||
|
||||
export async function processImage(
|
||||
bucket: string,
|
||||
@ -51,6 +52,8 @@ export async function processImage(
|
||||
}
|
||||
|
||||
try {
|
||||
await sleepWithCountdown(5);
|
||||
|
||||
// 🖼️ Create thumbnail
|
||||
const thumb = await sharp(buffer).resize(200).toBuffer();
|
||||
await writeImage(`${filePath}/thumbs/${fileName}`, thumb, mime);
|
||||
|
||||
28
util.ts
Normal file
28
util.ts
Normal file
@ -0,0 +1,28 @@
|
||||
export function sleepWithCountdown(seconds: number): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
let remaining = seconds;
|
||||
|
||||
const update = () => {
|
||||
const msg = `⏳ Waiting ${remaining}s...`;
|
||||
process.stdout.clearLine(0); // Clear current line
|
||||
process.stdout.cursorTo(0); // Move cursor to start of line
|
||||
process.stdout.write(msg); // Write message
|
||||
};
|
||||
|
||||
update(); // Initial message
|
||||
|
||||
const interval = setInterval(() => {
|
||||
remaining--;
|
||||
|
||||
if (remaining > 0) {
|
||||
update();
|
||||
} else {
|
||||
clearInterval(interval);
|
||||
process.stdout.clearLine(0);
|
||||
process.stdout.cursorTo(0);
|
||||
process.stdout.write(`✅ Resuming now\n`);
|
||||
resolve();
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user