Merge pull request #643 from RocketChat/cron
Automate statistics generation and send statistics to Rocket.Chat, unless opt-out.pull/646/head
commit
0d0044bc73
@ -1,2 +1,2 @@ |
||||
RocketChat.checkUsernameAvailability = (username) -> |
||||
return not Meteor.users.findOne({ username: { $regex : new RegExp("^" + _.trim(username) + "$", "i") } }) |
||||
return not Meteor.users.findOne({ username: { $regex : new RegExp("^" + s.trim(username) + "$", "i") } }) |
||||
@ -1,5 +0,0 @@ |
||||
RocketChat.saveStatistics = -> |
||||
statistics = RocketChat.getStatistics() |
||||
statistics.createdAt = new Date |
||||
Statistics.insert statistics |
||||
return statistics |
||||
@ -1,11 +0,0 @@ |
||||
Meteor.methods |
||||
generateStatistics: -> |
||||
if not Meteor.userId() |
||||
throw new Meteor.Error('invalid-user', "[methods] generateStatistics -> Invalid user") |
||||
|
||||
console.log '[methods] generateStatistics -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments |
||||
|
||||
unless Meteor.user()?.admin is true |
||||
throw new Meteor.Error 'not-authorized', '[methods] setAdminStatus -> Not authorized' |
||||
|
||||
return RocketChat.getStatistics() |
||||
@ -0,0 +1,3 @@ |
||||
{ |
||||
|
||||
} |
||||
@ -0,0 +1 @@ |
||||
RocketChat.statistics = {} |
||||
@ -0,0 +1,36 @@ |
||||
Package.describe({ |
||||
name: 'rocketchat:statistics', |
||||
version: '0.0.1', |
||||
summary: 'Statistics generator', |
||||
git: '' |
||||
}); |
||||
|
||||
Package.onUse(function(api) { |
||||
api.versionsFrom('1.0'); |
||||
|
||||
api.use([ |
||||
'templating', |
||||
'coffeescript', |
||||
'rocketchat:lib@0.0.1' |
||||
]); |
||||
|
||||
// TAPi18n
|
||||
api.use(["tap:i18n@1.5.1"], ["client", "server"]); |
||||
api.addFiles("package-tap.i18n", ["client", "server"]); |
||||
api.addFiles([ |
||||
"i18n/en.i18n.json", |
||||
], ["client", "server"]); |
||||
|
||||
// Statistics
|
||||
api.addFiles('lib/rocketchat.coffee', [ 'client', 'server' ]); |
||||
api.addFiles([ |
||||
'server/collections/Statistics.coffee', |
||||
'server/functions/get.coffee', |
||||
'server/functions/save.coffee' |
||||
], 'server'); |
||||
|
||||
}); |
||||
|
||||
Package.onTest(function(api) { |
||||
|
||||
}); |
||||
@ -0,0 +1 @@ |
||||
@MapReducedStatistics = new Meteor.Collection 'rocketchat_mr_statistics' |
||||
@ -0,0 +1 @@ |
||||
@Statistics = new Meteor.Collection 'rocketchat_statistics' |
||||
@ -0,0 +1,6 @@ |
||||
RocketChat.statistics.save = -> |
||||
statistics = RocketChat.statistics.get() |
||||
statistics.createdAt = new Date |
||||
Statistics.insert statistics |
||||
return statistics |
||||
|
||||
@ -0,0 +1,11 @@ |
||||
Meteor.methods |
||||
getStatistics: -> |
||||
if not Meteor.userId() |
||||
throw new Meteor.Error('invalid-user', "[methods] getStatistics -> Invalid user") |
||||
|
||||
console.log '[methods] getStatistics -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments |
||||
|
||||
unless Meteor.user()?.admin is true |
||||
throw new Meteor.Error 'not-authorized', '[methods] getStatistics -> Not authorized' |
||||
|
||||
return RocketChat.statistics.get() |
||||
@ -0,0 +1,22 @@ |
||||
# Config and Start SyncedCron |
||||
SyncedCron.config |
||||
collectionName: 'rocketchat_cron_history' |
||||
|
||||
Meteor.startup -> |
||||
Meteor.defer -> |
||||
|
||||
# Generate and save statistics every hour |
||||
SyncedCron.add |
||||
name: 'Generate and save statistics', |
||||
schedule: (parser) -># parser is a later.parse object |
||||
return parser.text 'every 1 hour' |
||||
job: -> |
||||
statistics = RocketChat.statistics.save() |
||||
unless RocketChat.settings.get 'Statistics_opt_out' |
||||
console.log 'Sending statistics data to Rocket.Chat' |
||||
HTTP.post 'https://rocket.chat/stats', |
||||
data: statistics |
||||
|
||||
return |
||||
|
||||
SyncedCron.start() |
||||
Loading…
Reference in new issue