'use strict';

const Promise = require('bluebird');
const pid = require('../src/util/pid');
const connection = require('../src/mongo/connection');

pid.start();

const source = require('../src/source/source');
const config = require('../src/config/config').globalConfig;

const sources = Object.keys(config.source);

if (sources.length === 0) {
    console.log('no source found in config');
}

Promise.coroutine(function* () {
    yield connection();
    for (const collection of sources) {
        const options = config.source[collection];
        try{
            yield source.copy(Object.assign({collection}, options));
        }catch(e){
            console.error(e);
        }
    }
})().then(function () {
    console.log('finished');
    return 0;
}, function (e) {
    console.error(e);
    return 1;
}).then(pid.stop);

@@ -139,16 +139,74 @@
 ction');
+%0Aconst debug = require('../src/util/debug')('bin:source');
 %0A%0Apid.st
@@ -538,24 +538,116 @@
  sources) %7B%0A
+        let start = new Date().getTime();%0A        debug(%60Begin sourcing of $%7Bcollection%7D%60);%0A
         cons
@@ -812,24 +812,24 @@
 e.error(e);%0A
-
         %7D%0A  
@@ -826,16 +826,149 @@
       %7D%0A
+        let end = new Date().getTime();%0A        let time = end - start;%0A        debug(%60End sourcing of $%7Bcollection%7D in $%7Btime%7Dms%60);%0A
     %7D%0A%7D)

add trace by step