diff --git a/src/invidious/helpers/tokenmon.cr b/src/invidious/helpers/tokenmon.cr new file mode 100644 index 00000000..58aeb2ce --- /dev/null +++ b/src/invidious/helpers/tokenmon.cr @@ -0,0 +1,40 @@ +class Invidious::TokenMon + + @@instance = new + + def self.pot + @@pot + end + + def self.vdata + @@vdata + end + + def initialize + + @@pot = "error" + @@vdata = "error" + + end + + def self.get_tokens + + # Load config from file or YAML string env var + env_config_file = "INVIDIOUS_CONFIG_FILE" + env_config_yaml = "INVIDIOUS_CONFIG" + + config_file = ENV.has_key?(env_config_file) ? ENV.fetch(env_config_file) : "config/config.yml" + config_yaml = ENV.has_key?(env_config_yaml) ? ENV.fetch(env_config_yaml) : File.read(config_file) + + config = Config.from_yaml(config_yaml) + + @@pot = config.po_token + @@vdata = config.visitor_data + + end + + def self.get_instance + return @@instance + end + +end \ No newline at end of file diff --git a/src/invidious/jobs/tokenmon.cr b/src/invidious/jobs/tokenmon.cr new file mode 100644 index 00000000..b96c5557 --- /dev/null +++ b/src/invidious/jobs/tokenmon.cr @@ -0,0 +1,17 @@ + +class Invidious::Jobs::MonitorCfgTokensJob < Invidious::Jobs::BaseJob + include Invidious + def begin + loop do + + LOGGER.info("jobs: running MonitorCfgTokensJob job") + + Invidious::TokenMon.get_tokens + + LOGGER.info("jobs: MonitorCfgTokensJob: pot: " + Invidious::TokenMon.pot.as(String)) + LOGGER.info("jobs: MonitorCfgTokensJob: vdata: " + Invidious::TokenMon.vdata.as(String)) + + sleep 1.minutes + end + end +end