2020-10-06 10:11:18 +05:30
|
|
|
module Invidious::Jobs
|
|
|
|
JOBS = [] of BaseJob
|
|
|
|
|
2022-10-12 13:36:36 +05:30
|
|
|
# Automatically generate a structure that wraps the various
|
|
|
|
# jobs' configs, so that the follwing YAML config can be used:
|
|
|
|
#
|
|
|
|
# jobs:
|
|
|
|
# job_name:
|
|
|
|
# enabled: true
|
|
|
|
# some_property: "value"
|
|
|
|
#
|
|
|
|
macro finished
|
|
|
|
struct JobsConfig
|
|
|
|
include YAML::Serializable
|
|
|
|
|
|
|
|
{% for sc in BaseJob.subclasses %}
|
|
|
|
# Voodoo macro to transform `Some::Module::CustomJob` to `custom`
|
|
|
|
{% class_name = sc.id.split("::").last.id.gsub(/Job$/, "").underscore %}
|
|
|
|
|
|
|
|
getter {{ class_name }} = {{ sc.name }}::Config.new
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-06 10:11:18 +05:30
|
|
|
def self.register(job : BaseJob)
|
|
|
|
JOBS << job
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.start_all
|
|
|
|
JOBS.each do |job|
|
2022-10-12 13:36:36 +05:30
|
|
|
# Don't run the main rountine if the job is disabled by config
|
|
|
|
next if job.disabled?
|
|
|
|
|
2020-10-06 10:11:18 +05:30
|
|
|
spawn { job.begin }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|