Skip to content

Instantly share code, notes, and snippets.

@roelvan
Last active September 1, 2015 21:36
Show Gist options
  • Save roelvan/28f89524f8fcc5e5177a to your computer and use it in GitHub Desktop.
Save roelvan/28f89524f8fcc5e5177a to your computer and use it in GitHub Desktop.
# on the server: server.coffee
Metrics = (name, aggregationQuery, collection, interval) ->
@name = name
@aggregationQuery = aggregationQuery
@collection = collection
@interval = interval or 1000*10
@_collectionName = 'metrics-transport'
Metrics.prototype._getCollectionName = -> "metrics-#{@name}"
Metrics.prototype._publishCursor = (sub) ->
result = @collection.aggregate @aggregationQuery
sub.added @_collectionName, @name, result: result
sub.ready()
handle = Meteor.setInterval =>
result = @collection.aggregate @aggregationQuery
sub.changed @_collectionName, @name, result: result
, @interval
sub.onStop -> Meteor.clearTimeout handle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment