annotate 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
rev   line source
19
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
1 # Copyright (C) 2014 by Intevation GmbH
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
2 # Author: Mathias Gebbe <mgebbe@intevation.de>
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
3 #
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
4 # This file is Free Software under the Apache License, Version 2.0;
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
5 # and comes with NO WARRANTY!
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
6 # See the documentation coming with pumpbridge for details.
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
7
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
8 _ = require("underscore")
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
9 async = require("async")
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
10 Facebook = require("./facebook")
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
11 Usermap = require("./usermap")
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
12 Google = require("./google")
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
13 Config = require ("./config")
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
14 config = Config.config
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
15 Twitter = require("./twitter")(config)
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
16
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
17 databank = require("databank")
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
18 Databank = databank.Databank
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
19 DatabankObject = databank.DatabankObject
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
20
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
21 db = Databank.get(config.driver, config.params)
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
22 DatabankObject.bank = db
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
23
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
24 syncFromESN = () ->
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
25 console.log 'syncFromESN'
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
26
21
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
27 ####
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
28 # Facebook
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
29 try
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
30 Usermap.scan ((user) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
31 if user.id.indexOf('@facebook') isnt -1
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
32 console.log "start sync for facebook user"
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
33 Facebook.sync(user)
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
34 ), (err) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
35 catch err
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
36 console.log 'Error!' + err
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
37
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
38 # Twitter
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
39 try
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
40 Usermap.scan ((user) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
41 if user.id.indexOf('@twitter') isnt -1
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
42 console.log "start sync for twitter user"
22
b90e6df48d2d eachLimit instead of each
Mathias Gebbe <mgebbe@intevation.de>
parents: 21
diff changeset
43 Twitter.syncToESN(user)
b90e6df48d2d eachLimit instead of each
Mathias Gebbe <mgebbe@intevation.de>
parents: 21
diff changeset
44 Twitter.syncFromESN(user)
21
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
45 ), (err) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
46 catch err
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
47 console.log 'Error!' + err
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
48
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
49 # Google
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
50 try
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
51 Usermap.scan ((user) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
52 if user.id.indexOf('@google') isnt -1
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
53 console.log "start sync for google user"
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
54 Google.sync(user)
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
55 ), (err) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
56 catch err
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
57 console.log 'Error!' + err
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
58 ####
19
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
59
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
60 return
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
61
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
62 sync = () ->
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
63
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
64 # Do this every xx minutes
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
65 console.log '\n\n\n' + "starting sync deamon"
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
66 interval = config.interval
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
67 if not (interval?)
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
68 interval = 15 * 60 * 1000 # 900 000 ms (15min)
22
b90e6df48d2d eachLimit instead of each
Mathias Gebbe <mgebbe@intevation.de>
parents: 21
diff changeset
69
21
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
70 async.waterfall [
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
71 (callback) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
72 db.connect(config.params, callback)
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
73 ], (err, result) ->
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
74 setInterval syncFromESN, interval
dbe2232af20f changed syncALONE
Mathias Gebbe <mgebbe@intevation.de>
parents: 20
diff changeset
75 syncFromESN()
19
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
76
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
77 return
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
78
6b3f38af3fa4 use child_process for backend
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
79 sync()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)