diff --git a/tvapp2/index.js b/tvapp2/index.js index 909f6d6b..ce824600 100755 --- a/tvapp2/index.js +++ b/tvapp2/index.js @@ -13,6 +13,7 @@ import chalk from 'chalk'; import ejs from 'ejs'; import moment from 'moment'; import cron, { schedule } from 'node-cron'; +import * as crons from 'cron'; /* Old CJS variables converted to ESM @@ -1764,9 +1765,24 @@ async function initialize() const start = performance.now(); try { - Log.info( `core`, chalk.yellow( `[schedule]` ), chalk.white( `ℹ️` ), - chalk.blueBright( `` ), chalk.gray( `Container set to refresh IPTV data on specified cron duration` ), - chalk.blueBright( `` ), chalk.whiteBright.bgBlack( ` ${ envTaskCronSync } ` ) ); + const validation = crons.validateCronExpression( envTaskCronSync ); + if ( !validation.valid ) + { + Log.error( `core`, chalk.yellow( `[schedule]` ), chalk.white( `❌` ), + chalk.redBright( `` ), chalk.gray( `Specified cron schedule is not valid` ), + chalk.redBright( `` ), chalk.whiteBright.bgBlack( ` ${ envTaskCronSync } ` ) ); + } + else + { + const cronNextRunDt = new Date( crons.sendAt( envTaskCronSync ) ); + const cronNextRun = moment( cronNextRunDt ).format( 'MM-DD-YYYY h:mm A' ); + + Log.info( `core`, chalk.yellow( `[schedule]` ), chalk.white( `ℹ️` ), + chalk.blueBright( `` ), chalk.gray( `TVApp2 will refresh channel and guide data at` ), + chalk.blueBright( `` ), chalk.whiteBright.gray( ` ${ envTaskCronSync } ` ), + chalk.blueBright( `` ), chalk.whiteBright.gray( ` ${ cronNextRun } ` ), + chalk.blueBright( `` ), chalk.whiteBright.gray( ` ${ cronNextRunDt } ` ) ); + } Log.info( `core`, chalk.yellow( `[initiate]` ), chalk.white( `ℹ️` ), chalk.blueBright( `` ), chalk.gray( `Starting TVApp2 container. Assigning bound IP to host network adapter` ), @@ -2312,7 +2328,7 @@ const server = http.createServer( ( request, response ) => })(); /* - Initialize Cron + Crons > Next Sync */ cron.schedule( envTaskCronSync, async() => @@ -2323,3 +2339,31 @@ cron.schedule( envTaskCronSync, async() => await initialize(); }); + +/* + Crons > Announce Next Sync + should show every 30 minutes +*/ + +cron.schedule( '*/30 * * * *', async() => +{ + const validation = crons.validateCronExpression( envTaskCronSync ); + if ( !validation.valid ) + { + Log.error( `core`, chalk.yellow( `[schedule]` ), chalk.white( `❌` ), + chalk.redBright( `` ), chalk.gray( `Specified cron schedule is not valid. Re-write the cron so that it is properly formatted` ), + chalk.redBright( `` ), chalk.gray( `TASK_CRON_SYNC` ), + chalk.redBright( `` ), chalk.whiteBright.bgBlack( ` ${ envTaskCronSync } ` ) ); + } + else + { + const cronNextRunDt = new Date( crons.sendAt( envTaskCronSync ) ); + const cronNextRun = moment( cronNextRunDt ).format( 'MM-DD-YYYY h:mm A' ); + + Log.info( `core`, chalk.yellow( `[schedule]` ), chalk.white( `ℹ️` ), + chalk.blueBright( `` ), chalk.gray( `Next IPTV data refresh at` ), + chalk.blueBright( `` ), chalk.whiteBright.gray( ` ${ envTaskCronSync } ` ), + chalk.blueBright( `` ), chalk.whiteBright.gray( ` ${ cronNextRun } ` ), + chalk.blueBright( `` ), chalk.whiteBright.gray( ` ${ cronNextRunDt } ` ) ); + } +}); diff --git a/tvapp2/package-lock.json b/tvapp2/package-lock.json index 00a6ca1f..515800c8 100755 --- a/tvapp2/package-lock.json +++ b/tvapp2/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "chalk": "^5.3.0", + "cron": "^4.3.0", "ejs": "^3.1.10", "express": "5.1.0", "moment": "2.30.1", @@ -298,6 +299,12 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/luxon": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.6.2.tgz", + "integrity": "sha512-R/BdP7OxEMc44l2Ex5lSXHoIXTB2JLNa3y2QISIbr58U/YcsffyQrYW//hZSdrfxrjRZj3GcUoxMPGdO8gSYuw==", + "license": "MIT" + }, "node_modules/@types/uuid": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", @@ -843,6 +850,19 @@ "node": ">=6.6.0" } }, + "node_modules/cron": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/cron/-/cron-4.3.0.tgz", + "integrity": "sha512-ciiYNLfSlF9MrDqnbMdRWFiA6oizSF7kA1osPP9lRzNu0Uu+AWog1UKy7SkckiDY2irrNjeO6qLyKnXC8oxmrw==", + "license": "MIT", + "dependencies": { + "@types/luxon": "~3.6.0", + "luxon": "~3.6.0" + }, + "engines": { + "node": ">=18.x" + } + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", @@ -2930,6 +2950,15 @@ "dev": true, "license": "MIT" }, + "node_modules/luxon": { + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.6.1.tgz", + "integrity": "sha512-tJLxrKJhO2ukZ5z0gyjY1zPh3Rh88Ej9P7jNrZiHMUXHae1yvI2imgOZtL1TO8TW6biMMKfTtAOoEJANgtWBMQ==", + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", diff --git a/tvapp2/package.json b/tvapp2/package.json index 17edc5d4..91f072be 100755 --- a/tvapp2/package.json +++ b/tvapp2/package.json @@ -72,6 +72,7 @@ "iptv" ], "dependencies": { + "cron": "^4.3.0", "node-cron": "^4.0.3", "playwright": "^1.52.0", "user-agents": "^1.1.537",