view src/syncALONE.coffee @ 23:8c56fdbac0fb

wrong return causes error!
author Mathias Gebbe <mgebbe@intevation.de>
date Wed, 18 Jun 2014 13:09:13 +0200
parents b90e6df48d2d
children f27ddfa42e94
line wrap: on
line source
# Copyright (C) 2014 by Intevation GmbH
# Author: Mathias Gebbe <mgebbe@intevation.de>
#
# This file is Free Software under the Apache License, Version 2.0;
# and comes with NO WARRANTY!
# See the documentation coming with pumpbridge for details.

_ = require("underscore")
async = require("async")
Facebook = require("./facebook")
Usermap = require("./usermap")
Google = require("./google")
Config = require ("./config")
config = Config.config
Twitter = require("./twitter")(config)

databank = require("databank")
Databank = databank.Databank
DatabankObject = databank.DatabankObject

db = Databank.get(config.driver, config.params)
DatabankObject.bank = db

syncFromESN = () ->
  console.log 'syncFromESN'

  ####
  # Facebook
  try
    Usermap.scan ((user) ->
      if user.id.indexOf('@facebook') isnt -1
        console.log "start sync for facebook user"
        Facebook.sync(user)
    ), (err) ->
  catch err
    console.log 'Error!' + err

  # Twitter
  try
    Usermap.scan ((user) ->
      if user.id.indexOf('@twitter') isnt -1
        console.log "start sync for twitter user"
        Twitter.syncToESN(user)
        Twitter.syncFromESN(user)
    ), (err) ->
  catch err
    console.log 'Error!' + err

  # Google
  try
    Usermap.scan ((user) ->
      if user.id.indexOf('@google') isnt -1
        console.log "start sync for google user"
        Google.sync(user)
    ), (err) ->
  catch err
    console.log 'Error!' + err
  ####

  return

sync = () ->

  # Do this every xx minutes
  console.log '\n\n\n' + "starting sync deamon"
  interval = config.interval
  if not (interval?)
    interval =  15 * 60 * 1000 # 900 000 ms (15min)

  async.waterfall [
    (callback) ->
       db.connect(config.params, callback)
  ], (err, result) ->
    setInterval syncFromESN, interval
    syncFromESN()

  return

sync()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)