| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- const Slack = require('./slack.js').Slack
- ,INACTIVE_DELAY = 120000
- ,PING_DELAY = 600000
- ,RTM_PING_DELAY = 15000
- ;
- function SlackManager() {
- this.cache = require('memory-cache');
- }
- var instance = new SlackManager();
- setInterval(function() {
- var keys = instance.cache.keys();
- keys.forEach(function(instKey) {
- instance.cache.get(instKey).ping();
- });
- }, PING_DELAY);
- setInterval(function() {
- var keys = instance.cache.keys();
- keys.forEach(function(instKey) {
- instance.cache.get(instKey).rtmPing();
- });
- }, RTM_PING_DELAY);
- SlackManager.prototype.getScope = function() {
- return [
- "client"
- ];
- };
- SlackManager.prototype.lazyGet = function(sess, reqT) {
- var key = "SLACK_" +sess.sessId
- ,val = this.cache.get(key);
- if (val) {
- this.cache.put(key, val, INACTIVE_DELAY, function(key, val) {
- instance.removed(key, val);
- });
- } else {
- val = new Slack(sess, this);
- this.cache.put(key, val, INACTIVE_DELAY, function(key, val) {
- instance.removed(key, val);
- val.close();
- });
- }
- return val;
- };
- SlackManager.prototype.removed = function(key, slack) {
- slack.close();
- };
- SlackManager.prototype.suicide = function(slack) {
- this.cache.del("SLACK_" +slack.sessId);
- };
- module.exports.SlackManager = instance;
|