Add table cleaning job (#3294)
parent
6707368f19
commit
3b39b8c772
@ -1,3 +1,33 @@
|
||||
abstract class Invidious::Jobs::BaseJob
|
||||
abstract def begin
|
||||
|
||||
# When this base job class is inherited, make sure to define
|
||||
# a basic "Config" structure, that contains the "enable" property,
|
||||
# and to create the associated instance property.
|
||||
#
|
||||
macro inherited
|
||||
macro finished
|
||||
# This config structure can be expanded as required.
|
||||
struct Config
|
||||
include YAML::Serializable
|
||||
|
||||
property enable = true
|
||||
|
||||
def initialize
|
||||
end
|
||||
end
|
||||
|
||||
property cfg = Config.new
|
||||
|
||||
# Return true if job is enabled by config
|
||||
protected def enabled? : Bool
|
||||
return (@cfg.enable == true)
|
||||
end
|
||||
|
||||
# Return true if job is disabled by config
|
||||
protected def disabled? : Bool
|
||||
return (@cfg.enable == false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,27 @@
|
||||
class Invidious::Jobs::ClearExpiredItemsJob < Invidious::Jobs::BaseJob
|
||||
# Remove items (videos, nonces, etc..) whose cache is outdated every hour.
|
||||
# Removes the need for a cron job.
|
||||
def begin
|
||||
loop do
|
||||
failed = false
|
||||
|
||||
LOGGER.info("jobs: running ClearExpiredItems job")
|
||||
|
||||
begin
|
||||
Invidious::Database::Videos.delete_expired
|
||||
Invidious::Database::Nonces.delete_expired
|
||||
rescue DB::Error
|
||||
failed = true
|
||||
end
|
||||
|
||||
# Retry earlier than scheduled on DB error
|
||||
if failed
|
||||
LOGGER.info("jobs: ClearExpiredItems failed. Retrying in 10 minutes.")
|
||||
sleep 10.minutes
|
||||
else
|
||||
LOGGER.info("jobs: ClearExpiredItems done.")
|
||||
sleep 1.hour
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue