Skip to content

Commit

Permalink
add uptime to worker
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-flip committed Dec 24, 2023
1 parent 8ece31f commit ba09bad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
env:
token_discord: ${{ secrets.DISCORD_BOT_TOKEN }}
token_uptime: ${{secrets.TOKEN_UPTIME}}
token_uptime_worker: ${{secrets.TOKEN_UPTIME_WORKER}}
token_botsondiscord: ${{secrets.TOKEN_BOTSONDISCORD}}
token_discordbotlist: ${{secrets.TOKEN_DISCORDBOTLIST}}
token_discords: ${{secrets.TOKEN_DISCORDS}}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ services:
- db-feb
restart: always
environment:
token_uptime_worker: ${token_uptime_worker}
login_fa_cookie_a: ${login_fa_cookie_a}
login_fa_cookie_b: ${login_fa_cookie_b}
db_dialect: mysql
Expand Down
4 changes: 3 additions & 1 deletion workers/faAutopost/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"intervalChecker": 1.8e+6
"intervalChecker": 1.8e+6,
"uptimeInterval": 60,
"uptimeEndpoint": "https://status.flipped.codes/api/push/"
}
10 changes: 10 additions & 0 deletions workers/faAutopost/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import PQueue from 'p-queue';

import Sequelize from 'sequelize';

import https from 'https';

import { main as intAutopostfasubmission } from './database/models/autopostfasubmission.js';

import { main as intPostfacache } from './database/models/postfacache.js';
Expand All @@ -16,6 +18,12 @@ const DEBUG = process.env.NODE_ENV === 'development';

let del = [];

function uptimeHeartbeat() {
setInterval(() => {
https.get(`${config.uptimeEndpoint}${process.env.token_uptime_worker}?status=up&msg=OK`);
}, config.uptimeInterval * 1000);
}

// removes submissions from FA inbox, if they have been imported
async function cleanupDonePosts() {
setInterval(async () => {
Expand Down Expand Up @@ -69,6 +77,8 @@ const postfacache = intPostfacache(sequelize);
await sequelize.sync();
// login FA
await Login(process.env.login_fa_cookie_a, process.env.login_fa_cookie_b);
// startup uptime monitoring
uptimeHeartbeat();
// startup cleaner interval
cleanupDonePosts();

Expand Down

0 comments on commit ba09bad

Please sign in to comment.