mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-24 22:46:41 +07:00
#5 added healthcheck
This commit is contained in:
parent
46d24cd9dd
commit
dd3c281af9
6 changed files with 37 additions and 4 deletions
|
@ -27,6 +27,10 @@ services:
|
|||
entrypoint: ./wait-for-it.sh -t 90 db:5432 -- node ./index.js
|
||||
depends_on:
|
||||
- db
|
||||
healthcheck:
|
||||
test: [ "CMD", "curl", "-f", "http://localhost", "||", "kill", "-s", "2", "1" ]
|
||||
interval: 5m
|
||||
timeout: 1m
|
||||
volumes:
|
||||
bot-db:
|
||||
node_modules:
|
||||
|
|
|
@ -53,11 +53,12 @@ export class HttpApi {
|
|||
const url = new URL(this.webhook.url);
|
||||
logger.info(`using webhook at ${url.pathname}`);
|
||||
this.app.post(url.pathname, this.handleWebhook);
|
||||
this.app.get(url.pathname, this.testWebhook);
|
||||
this.app.get(url.pathname, this.healthcheck);
|
||||
}
|
||||
|
||||
// VK event handler
|
||||
this.app.post(this.vk.endpoint, this.vk.handle);
|
||||
this.app.get("/", this.healthcheck);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,7 +72,12 @@ export class HttpApi {
|
|||
/**
|
||||
* Just returns 200
|
||||
*/
|
||||
private testWebhook = async (req: Request, res: Response) => {
|
||||
res.sendStatus(200);
|
||||
private healthcheck = async (req: Request, res: Response) => {
|
||||
try {
|
||||
await Promise.all([this.telegram.healthcheck(), this.vk.healthcheck()]);
|
||||
res.sendStatus(200);
|
||||
} catch (e) {
|
||||
res.sendStatus(501);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -43,4 +43,5 @@ export interface Storage {
|
|||
vkPostId: number
|
||||
): Promise<Post | undefined>;
|
||||
findPostByEvent(eventId: number): Promise<Post | undefined>;
|
||||
healthcheck(): Promise<void>;
|
||||
}
|
||||
|
|
|
@ -127,4 +127,8 @@ export class PostgresDB implements Storage {
|
|||
createPost = async (eventId: number, text: string, vkPostId: number) => {
|
||||
return this.posts.save({ eventId, text, vkPostId });
|
||||
};
|
||||
|
||||
healthcheck = async () => {
|
||||
await this.connection.query("SELECT 1");
|
||||
};
|
||||
}
|
||||
|
|
|
@ -96,11 +96,22 @@ export class TelegramService {
|
|||
});
|
||||
};
|
||||
|
||||
stop = (signal: string) => {
|
||||
/**
|
||||
* Stops service
|
||||
* @param signal
|
||||
*/
|
||||
public stop = (signal: string) => {
|
||||
if (!this.isWebhookEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bot.stop(signal);
|
||||
};
|
||||
|
||||
/**
|
||||
* Performs healthcheck for telegram
|
||||
*/
|
||||
public healthcheck = async () => {
|
||||
await this.bot.telegram.getMe();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -133,4 +133,11 @@ export class VkService {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs healthcheck for telegram
|
||||
*/
|
||||
public healthcheck = async () => {
|
||||
await this.db.healthcheck();
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue