Mercurial > pumpbridge
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 | 27 #### |
28 # Facebook | |
29 try | |
30 Usermap.scan ((user) -> | |
31 if user.id.indexOf('@facebook') isnt -1 | |
32 console.log "start sync for facebook user" | |
33 Facebook.sync(user) | |
34 ), (err) -> | |
35 catch err | |
36 console.log 'Error!' + err | |
37 | |
38 # Twitter | |
39 try | |
40 Usermap.scan ((user) -> | |
41 if user.id.indexOf('@twitter') isnt -1 | |
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 | 45 ), (err) -> |
46 catch err | |
47 console.log 'Error!' + err | |
48 | |
49 # Google | |
50 try | |
51 Usermap.scan ((user) -> | |
52 if user.id.indexOf('@google') isnt -1 | |
53 console.log "start sync for google user" | |
54 Google.sync(user) | |
55 ), (err) -> | |
56 catch err | |
57 console.log 'Error!' + err | |
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 | 70 async.waterfall [ |
71 (callback) -> | |
72 db.connect(config.params, callback) | |
73 ], (err, result) -> | |
74 setInterval syncFromESN, interval | |
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() |