Skip to content

Commit f75a81c

Browse files
committed
Make configurable time between each RefreshChannelsJob
1 parent 85ba04b commit f75a81c

File tree

5 files changed

+47
-20
lines changed

5 files changed

+47
-20
lines changed

config/config.example.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ https_only: false
314314
##
315315
channel_threads: 1
316316

317+
##
318+
## Time between channel_refresh
319+
##
320+
## Accepted values: a valid time interval (hours:min:seconds)
321+
## Default: 00:30:00
322+
##
323+
channel_refresh_time: 00:30:00
324+
317325
##
318326
## Forcefully dump and re-download the entire list of uploaded
319327
## videos when crawling channel (during subscriptions update).

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ services:
2323
environment:
2424
# Adapted from ./config/config.yml
2525
INVIDIOUS_CONFIG: |
26+
log_level: Info
2627
channel_threads: 1
28+
channel_refresh_time: 00:30:00
2729
check_tables: true
2830
feed_threads: 1
2931
db:

src/invidious/config.cr

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ end
5656
class Config
5757
include YAML::Serializable
5858

59-
property channel_threads : Int32 = 1 # Number of threads to use for crawling videos from channels (for updating subscriptions)
60-
property feed_threads : Int32 = 1 # Number of threads to use for updating feeds
61-
property output : String = "STDOUT" # Log file path or STDOUT
62-
property log_level : LogLevel = LogLevel::Info # Default log level, valid YAML values are ints and strings, see src/invidious/helpers/logger.cr
63-
property db : DBConfig? = nil # Database configuration with separate parameters (username, hostname, etc)
59+
property channel_threads : Int32 = 1 # Number of threads to use for crawling videos from channels (for updating subscriptions)
60+
@[YAML::Field(converter: TimeSpanConverter)]
61+
property channel_refresh_time : Time::Span = 30.minutes # Time between channel_refresh
62+
property feed_threads : Int32 = 1 # Number of threads to use for updating feeds
63+
property output : String = "STDOUT" # Log file path or STDOUT
64+
property log_level : LogLevel = LogLevel::Info # Default log level, valid YAML values are ints and strings, see src/invidious/helpers/logger.cr
65+
property db : DBConfig? = nil # Database configuration with separate parameters (username, hostname, etc)
6466

6567
@[YAML::Field(converter: Preferences::URIConverter)]
6668
property database_url : URI = URI.parse("") # Database configuration using 12-Factor "Database URL" syntax

src/invidious/helpers/utils.cr

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,39 @@ def elapsed_text(elapsed)
1818
"#{(millis * 1000).round(2)}µs"
1919
end
2020

21-
def decode_length_seconds(string)
22-
length_seconds = string.gsub(/[^0-9:]/, "")
23-
return 0_i32 if length_seconds.empty?
21+
module TimeSpanConverter
22+
def self.to_yaml(value : Time::Span, yaml : YAML::Nodes::Builder)
23+
return yaml.scalar recode_length_seconds(value.total_seconds.to_i32)
24+
end
2425

25-
length_seconds = length_seconds.split(":").map { |x| x.to_i? || 0 }
26-
length_seconds = [0] * (3 - length_seconds.size) + length_seconds
26+
def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Time::Span
27+
if node.is_a?(YAML::Nodes::Scalar)
28+
return decode_time_span(node.value)
29+
else
30+
node.raise "Expected scalar, not #{node.class}"
31+
end
32+
end
33+
end
2734

28-
length_seconds = Time::Span.new(
29-
hours: length_seconds[0],
30-
minutes: length_seconds[1],
31-
seconds: length_seconds[2]
32-
).total_seconds.to_i32
35+
def decode_time_span(string : String) : Time::Span
36+
time_span = string.gsub(/[^0-9:]/, "")
37+
return Time::Span.new(seconds: 0) if time_span.empty?
38+
39+
time_span = time_span.split(":").map { |x| x.to_i? || 0 }
40+
time_span = [0] * (3 - time_span.size) + time_span
41+
42+
return Time::Span.new(
43+
hours: time_span[0],
44+
minutes: time_span[1],
45+
seconds: time_span[2]
46+
)
47+
end
3348

34-
return length_seconds
49+
def decode_length_seconds(string : String) : Int32
50+
return decode_time_span(string).total_seconds.to_i32
3551
end
3652

37-
def recode_length_seconds(time)
53+
def recode_length_seconds(time : Int32) : String
3854
if time <= 0
3955
return ""
4056
else

src/invidious/jobs/refresh_channels_job.cr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ class Invidious::Jobs::RefreshChannelsJob < Invidious::Jobs::BaseJob
5858
end
5959
end
6060

61-
# TODO: make this configurable
62-
LOGGER.debug("RefreshChannelsJob: Done, sleeping for thirty minutes")
63-
sleep 30.minutes
61+
LOGGER.debug("RefreshChannelsJob: Done, sleeping for #{CONFIG.channel_refresh_time}")
62+
sleep CONFIG.channel_refresh_time
6463
Fiber.yield
6564
end
6665
end

0 commit comments

Comments
 (0)