summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFéry Mathieu (Mathius) <ferymathieuy@gmail.com>2022-02-21 10:53:20 +0100
committerFéry Mathieu (Mathius) <ferymathieuy@gmail.com>2022-02-21 10:53:20 +0100
commitf75a81c9eeb792c0b99075bc47a1243a23b8700b (patch)
tree7f60ef1a946a04347c4457b1807b07e9e31d1725 /src
parent85ba04b715f35e41585e9ef6bb873aaa2cc45a23 (diff)
downloadinvidious-f75a81c9eeb792c0b99075bc47a1243a23b8700b.tar.gz
invidious-f75a81c9eeb792c0b99075bc47a1243a23b8700b.tar.bz2
invidious-f75a81c9eeb792c0b99075bc47a1243a23b8700b.zip
Make configurable time between each RefreshChannelsJob
Diffstat (limited to 'src')
-rw-r--r--src/invidious/config.cr12
-rw-r--r--src/invidious/helpers/utils.cr40
-rw-r--r--src/invidious/jobs/refresh_channels_job.cr5
3 files changed, 37 insertions, 20 deletions
diff --git a/src/invidious/config.cr b/src/invidious/config.cr
index 72e145da..150f8064 100644
--- a/src/invidious/config.cr
+++ b/src/invidious/config.cr
@@ -56,11 +56,13 @@ end
class Config
include YAML::Serializable
- property channel_threads : Int32 = 1 # Number of threads to use for crawling videos from channels (for updating subscriptions)
- property feed_threads : Int32 = 1 # Number of threads to use for updating feeds
- property output : String = "STDOUT" # Log file path or STDOUT
- property log_level : LogLevel = LogLevel::Info # Default log level, valid YAML values are ints and strings, see src/invidious/helpers/logger.cr
- property db : DBConfig? = nil # Database configuration with separate parameters (username, hostname, etc)
+ property channel_threads : Int32 = 1 # Number of threads to use for crawling videos from channels (for updating subscriptions)
+ @[YAML::Field(converter: TimeSpanConverter)]
+ property channel_refresh_time : Time::Span = 30.minutes # Time between channel_refresh
+ property feed_threads : Int32 = 1 # Number of threads to use for updating feeds
+ property output : String = "STDOUT" # Log file path or STDOUT
+ property log_level : LogLevel = LogLevel::Info # Default log level, valid YAML values are ints and strings, see src/invidious/helpers/logger.cr
+ property db : DBConfig? = nil # Database configuration with separate parameters (username, hostname, etc)
@[YAML::Field(converter: Preferences::URIConverter)]
property database_url : URI = URI.parse("") # Database configuration using 12-Factor "Database URL" syntax
diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr
index a58a21b1..2702c5e9 100644
--- a/src/invidious/helpers/utils.cr
+++ b/src/invidious/helpers/utils.cr
@@ -18,23 +18,39 @@ def elapsed_text(elapsed)
"#{(millis * 1000).round(2)}µs"
end
-def decode_length_seconds(string)
- length_seconds = string.gsub(/[^0-9:]/, "")
- return 0_i32 if length_seconds.empty?
+module TimeSpanConverter
+ def self.to_yaml(value : Time::Span, yaml : YAML::Nodes::Builder)
+ return yaml.scalar recode_length_seconds(value.total_seconds.to_i32)
+ end
- length_seconds = length_seconds.split(":").map { |x| x.to_i? || 0 }
- length_seconds = [0] * (3 - length_seconds.size) + length_seconds
+ def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Time::Span
+ if node.is_a?(YAML::Nodes::Scalar)
+ return decode_time_span(node.value)
+ else
+ node.raise "Expected scalar, not #{node.class}"
+ end
+ end
+end
- length_seconds = Time::Span.new(
- hours: length_seconds[0],
- minutes: length_seconds[1],
- seconds: length_seconds[2]
- ).total_seconds.to_i32
+def decode_time_span(string : String) : Time::Span
+ time_span = string.gsub(/[^0-9:]/, "")
+ return Time::Span.new(seconds: 0) if time_span.empty?
+
+ time_span = time_span.split(":").map { |x| x.to_i? || 0 }
+ time_span = [0] * (3 - time_span.size) + time_span
+
+ return Time::Span.new(
+ hours: time_span[0],
+ minutes: time_span[1],
+ seconds: time_span[2]
+ )
+end
- return length_seconds
+def decode_length_seconds(string : String) : Int32
+ return decode_time_span(string).total_seconds.to_i32
end
-def recode_length_seconds(time)
+def recode_length_seconds(time : Int32) : String
if time <= 0
return ""
else
diff --git a/src/invidious/jobs/refresh_channels_job.cr b/src/invidious/jobs/refresh_channels_job.cr
index 55fb8154..3e04d1cd 100644
--- a/src/invidious/jobs/refresh_channels_job.cr
+++ b/src/invidious/jobs/refresh_channels_job.cr
@@ -58,9 +58,8 @@ class Invidious::Jobs::RefreshChannelsJob < Invidious::Jobs::BaseJob
end
end
- # TODO: make this configurable
- LOGGER.debug("RefreshChannelsJob: Done, sleeping for thirty minutes")
- sleep 30.minutes
+ LOGGER.debug("RefreshChannelsJob: Done, sleeping for #{CONFIG.channel_refresh_time}")
+ sleep CONFIG.channel_refresh_time
Fiber.yield
end
end