diff --git a/index.js b/index.js index f7dfb9a..b52814e 100644 --- a/index.js +++ b/index.js @@ -2,33 +2,37 @@ const { createTask } = require('./lib/task') const { fetchVisitorData } = require('./lib/workflow') const { Redis } = require('ioredis') - const redis = new Redis({ host: process.env.HOST || config.host }); redis.on('error', (error) => { - console.error('Could not connect to Redis:', error); - process.exit(1); + console.error('Could not connect to Redis:', error); + process.exit(1); }); const generate = async () => { - const visitorData = await fetchVisitorData() - const task = await createTask(visitorData) - const { poToken } = await task.start() - return { visitorData, poToken } + console.debug("[DEBUG] generate called") + try { + const visitorData = await fetchVisitorData() + const task = await createTask(visitorData) + const { poToken } = await task.start() + return { visitorData, poToken } + } catch (e) { + console.error(`generate: Error ${e}`) + } } const run = async () => { try { const { visitorData, poToken } = await generate(); - p = redis.set("invidious:po_token", poToken) - v = redis.set("invidious:visitor_data", visitorData) + redis.set("invidious:po_token", poToken) + redis.set("invidious:visitor_data", visitorData) } catch(e) { - console.error(`Fuck: ${e}`) + console.error(`run: Error ${e}`) } console.log("New tokens sent to redis") } run(); -setTimeout(run, (process.env.RENEW_INTERVAL || 60) * 1000) +setInterval(run, (process.env.RENEW_INTERVAL || 60) * 1000) module.exports = { generate }