auto-refresh data RQ jobs admin page (#4298)

This commit is contained in:
Omer Lachish 2019-11-11 09:42:05 +02:00 committed by GitHub
parent 80878abf7b
commit f19d24287e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,20 +25,29 @@ class Jobs extends React.Component {
workers: [],
};
_refreshTimer = null;
componentDidMount() {
recordEvent('view', 'page', 'admin/rq_status');
$http
.get('/api/admin/queries/rq_status')
.then(({ data }) => this.processQueues(data))
.catch(error => this.handleError(error));
this.refresh();
}
componentWillUnmount() {
// Ignore data after component unmounted
clearTimeout(this._refreshTimer);
this.processQueues = () => {};
this.handleError = () => {};
}
refresh = () => {
$http
.get('/api/admin/queries/rq_status')
.then(({ data }) => this.processQueues(data))
.catch(error => this.handleError(error));
this._refreshTimer = setTimeout(this.refresh, 60 * 1000);
};
processQueues = ({ queues, workers }) => {
const queueCounters = values(queues).map(({ started, ...rest }) => ({
started: started.length,