Project import generated by Copybara.
GitOrigin-RevId: d9e9e3fb4e31372ec1fb43b178994ca78fa8fe70
diff --git a/static_src/shared/cron.js b/static_src/shared/cron.js
new file mode 100644
index 0000000..bd67507
--- /dev/null
+++ b/static_src/shared/cron.js
@@ -0,0 +1,35 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import {store} from 'reducers/base.js';
+import * as sitewide from 'reducers/sitewide.js';
+
+// How long should we wait until asking the server status again.
+const SERVER_STATUS_DELAY_MS = 20 * 60 * 1000; // 20 minutes
+
+// CronTask is a class that supports periodically execution of tasks.
+export class CronTask {
+ constructor(task, delay) {
+ this.task = task;
+ this.delay = delay;
+ this.started = false;
+ }
+
+ start() {
+ if (this.started) return;
+ this.started = true;
+ this._execute();
+ }
+
+ _execute() {
+ this.task();
+ setTimeout(this._execute.bind(this), this.delay);
+ }
+}
+
+// getServerStatusCron requests status information from the server every 20
+// minutes.
+export const getServerStatusCron = new CronTask(
+ () => store.dispatch(sitewide.getServerStatus()),
+ SERVER_STATUS_DELAY_MS);