collect_data.js 869 Bytes
'use strict';

import Collect from '../../ci/collect_data';

import {
    Project
} from '../../models';

export default {
    async collect(ctx) {
        let projects,
            servers = {};

        setInterval(async() => {
            if (!projects) projects = await Project.findAll();
            if (!projects || !projects.length) {
                return;
            }

            projects.forEach(async(p) => {
                let hosts = p.deploy['production'].target;

                if (typeof hosts === 'string') {
                    hosts = [hosts];
                }
                hosts.forEach((host) => {
                    if (!servers[host]) {
                        servers[host] = new Collect(host, p.name);
                    }

                    servers[host].collect();
                });
            });
        }, 5000);
    }
};