Repository navigation
Expand file tree
/
Copy pathapp-scheduler.js
More file actions
executable file
·84 lines (70 loc) · 2.43 KB
/
Copy pathapp-scheduler.js
File metadata and controls
executable file
·84 lines (70 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
env = require('./env');
var JobManager = require('./lib/managers/JobManager')
, AWS = require('aws-sdk')
, Memcached = require('memcached')
, express = require('express')
, app = express()
, errorhandler = require('errorhandler')
;
rollbar = require('rollbar');
AWS.config.update({apiVersion:"2012-08-10"});
AWS.config.update({sslEnabled:false});
AWS.config.update({region:env.current.aws.region});
if( env.current.aws.endpoint ) {
AWS.config.update({endpoint:env.current.aws.endpoint});
}
dynamodb = new AWS.DynamoDB();
docClient = new AWS.DynamoDB.DocumentClient();
cacheNodes = [];
app_memcached = null;
cacheNodes.push( env.current.memcachedEndpoint );
app_memcached = new Memcached( cacheNodes );
app_memcached.on('failure', function( details ){ sys.error( "Server " + details.server + "went down due to: " + details.messages.join( '' ) ) });
app.set('port', process.env.PORT || 3080);
app.get('/jobrunner', function(req, res) {
JobManager.runJobs(function() { console.log("Finished running jobs."); res.sendStatus(200); });
});
app.get('/checkme', function(req, res) {
res.success({status: "ok"});
});
if( env.name != "development" ) {
rollbar.init("7bfa52938606455c87d52ed1909f9bfd", {
environment: env.name
});
app.use(rollbar.errorHandler('7bfa52938606455c87d52ed1909f9bfd'));
var rollBarOptions = {
// Call process.exit(1) when an uncaught exception occurs but after reporting all
// pending errors to Rollbar.
//
// Default: false
exitOnUncaughtException: true
};
rollbar.handleUncaughtExceptions("7bfa52938606455c87d52ed1909f9bfd", rollBarOptions);
} else {
app.use(errorhandler());
}
var server = app.listen(app.get('port'), function() {
console.log('Listening on port %d', server.address().port);
});
var typeformConfig = require( './lib/managers/typeform/typeform-config.json')
, quizConfigs = typeformConfig.quizConfigs
, TypeformManager = require('./lib/managers/TypeformManager.js')
;
var quizIds = [];
for(var quizId in quizConfigs) {
quizIds.push(quizId);
}
setInterval(function(){
"use strict";
for( let quizId of quizIds ) {
TypeformManager.updateQuizById(quizId, (err, data)=>{
if(err) {
console.log(err.message);
}
if(data) {
console.log(data);
}
});
}
JobManager.runJobs(function() { console.log("Finished running jobs."); });
}, 15 * 1000);