Make data source refresh interval configurable

This commit is contained in:
Max Goodhart
2020-07-27 11:23:26 -07:00
parent e8839db60d
commit 19a29e859f
3 changed files with 12 additions and 4 deletions

View File

@@ -27,6 +27,9 @@ username = "woke"
password = "woke"
[data]
# Interval to refresh polled datasources
#interval = 30
# By default, we use the woke.net streams data source.
# You can add other URLs to fetch here:
json-url = ["https://woke.net/api/streams.json"]

View File

@@ -12,8 +12,8 @@ function filterLive(data) {
return data.filter(({ status }) => status === 'Live' || status === 'Unknown')
}
export async function* pollDataURL(url) {
const refreshInterval = 5 * 1000
export async function* pollDataURL(url, intervalSecs) {
const refreshInterval = intervalSecs * 1000
let lastData = []
while (true) {
let data = []

View File

@@ -62,7 +62,12 @@ function parseArgs() {
describe: 'Background color of wall (useful for chroma-keying)',
default: '#000',
})
.group(['data.json-url', 'data.toml-file'], 'Datasources')
.group(['data.interval', 'data.json-url', 'data.toml-file'], 'Datasources')
.option('data.interval', {
describe: 'Interval (in seconds) for refreshing polled data sources',
number: true,
default: 30,
})
.option('data.json-url', {
describe: 'Fetch streams from the specified URL(s)',
array: true,
@@ -353,7 +358,7 @@ async function main() {
const dataSources = [
...argv.data['json-url'].map((url) =>
markDataSource(pollDataURL(url), 'json-url'),
markDataSource(pollDataURL(url, argv.data.interval), 'json-url'),
),
...argv.data['toml-file'].map((path) =>
markDataSource(watchDataFile(path), 'toml-file'),