2016-07-12 07:33:56 +08:00
|
|
|
// require('newrelic');
|
2016-06-20 15:19:16 +08:00
|
|
|
global.Promise = require('bluebird');
|
2016-07-09 08:13:30 +08:00
|
|
|
const {DatabaseConnector, Logger} = require(`nylas-core`)
|
2016-06-23 15:49:22 +08:00
|
|
|
const SyncProcessManager = require('./sync-process-manager');
|
2016-06-19 18:02:32 +08:00
|
|
|
|
2016-07-09 08:13:30 +08:00
|
|
|
global.Logger = Logger.createLogger('nylas-k2-sync')
|
|
|
|
|
2016-07-12 08:42:49 +08:00
|
|
|
const onUnhandledError = (err) => global.Logger.fatal(err, 'Unhandled error')
|
|
|
|
process.on('uncaughtException', onUnhandledError)
|
|
|
|
process.on('unhandledRejection', onUnhandledError)
|
|
|
|
|
2016-06-23 15:49:22 +08:00
|
|
|
const manager = new SyncProcessManager();
|
2016-06-22 09:29:58 +08:00
|
|
|
|
2016-06-23 15:49:22 +08:00
|
|
|
DatabaseConnector.forShared().then((db) => {
|
|
|
|
const {Account} = db;
|
|
|
|
Account.findAll().then((accounts) => {
|
|
|
|
if (accounts.length === 0) {
|
2016-07-09 08:13:30 +08:00
|
|
|
global.Logger.info(`Couldn't find any accounts to sync. Run this CURL command to auth one!`)
|
2016-07-12 05:23:20 +08:00
|
|
|
global.Logger.info(`curl -X POST -H "Content-Type: application/json" -d '{"email":"inboxapptest1@fastmail.fm", "name":"Ben Gotow", "provider":"imap", "settings":{"imap_username":"inboxapptest1@fastmail.fm","imap_host":"mail.messagingengine.com","imap_port":993,"smtp_host":"mail.messagingengine.com","smtp_port":0,"smtp_username":"inboxapptest1@fastmail.fm", "smtp_password":"trar2e","imap_password":"trar2e","ssl_required":true}}' "http://localhost:5100/auth?client_id=123"`)
|
2016-06-23 15:49:22 +08:00
|
|
|
}
|
|
|
|
manager.ensureAccountIDsInRedis(accounts.map(a => a.id)).then(() => {
|
|
|
|
manager.start();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
2016-06-19 18:02:32 +08:00
|
|
|
|
2016-06-23 15:49:22 +08:00
|
|
|
global.manager = manager;
|