import Promise from 'bluebird';
import co from 'co';
import { Logger } from 'eazy-logger';
import logUpdate from 'log-update';

import RemortInfluxConnector from './connector';

const logger = Logger({
  prefix: '{blue:[}{magenta:influx-agent}{blue:] }',
  useLevelPrefixes: true
});

const context = RemortInfluxConnector({ host: 'localhost', port: '32786' });

function* writeThings() {
  yield context.createDatabase('stock_pricing');
  yield context.writePoint([
    {
      measurement: 'response_times',
      tags: { host: 'os.hostnam()' },
      fields: { duration: 666, path: 'req.path' },
    }
  ]);
}

co(function* runInfluxTask() {
  yield context.connect('stock_pricing');
  yield* writeThings();
});

logUpdate('\n influx-agent Instance Start \n');

export default context;
