How to use the egg.Subscription function in egg

To help you get started, we’ve selected a few egg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github macacajs / macaca-datahub / app / schedule / backup_data.js View on Github external
'use strict';

const fs = require('mz/fs');
const path = require('path');
const Subscription = require('egg').Subscription;
const BACKUP_FILE_INFIX = '-backup-';
const BACKUP_LIMIT_NUMBER = 7;

class BackupData extends Subscription {

  static get schedule() {
    // backup at 00:00 every day.
    return {
      cron: '0 0 0 * * *',
      type: 'worker',
    };
  }

  async subscribe() {
    await this.removeOutdatedFiles();
    const storeFile = this.ctx.app.config.sequelize.storage;
github chrish-2017 / wechat_public_number_demo / app / schedule / access_token.js View on Github external
'use strict';

const Subscription = require('egg').Subscription;

class UpdateCache extends Subscription {
  static get schedule() {
    return {
      interval: '2h',
      type: 'all',
    };
  }

  async subscribe() {
    const config = this.ctx.app.config.wechat_config;
    const url = config.getAccessTokenUrl.replace('APPID', config.appId).replace('APPSECRET', config.appSecret);
    const res = await this.ctx.curl(url, {
      dataType: 'json',
    });
    console.log(res.data.access_token);
github eggjs / examples / schedule / app / schedule / all_cron.js View on Github external
'use strict';

const Subscription = require('egg').Subscription;

const now = new Date();
const start = (now.getSeconds() + 3) % 60;

class AllCron extends Subscription {
  async subscribe() {
    this.ctx.logger.info('all&&cron');
  }

  static get schedule() {
    return {
      cron: `${start}/30 * * * * *`,
      type: 'all',
    };
  }
}
github eggjs / examples / schedule / app / schedule / worker_cron.js View on Github external
'use strict';

const Subscription = require('egg').Subscription;

const now = new Date();
const start = (now.getSeconds() + 3) % 60;

class WorkerCron extends Subscription {
  async subscribe() {
    this.ctx.logger.info('worker&&cron');
  }

  static get schedule() {
    return {
      cron: `${start}/30 * * * * *`,
      type: 'worker',
    };
  }
}
github eggjs / examples / schedule / app / schedule / worker_interval.js View on Github external
'use strict';

const Subscription = require('egg').Subscription;

class WorkerInterval extends Subscription {
  async subscribe() {
    this.ctx.logger.info('all&&interval');
  }

  static get schedule() {
    return {
      interval: 3000,
      type: 'worker',
    };
  }
}

module.exports = WorkerInterval;
github eggjs / examples / schedule / app / schedule / all_interval.js View on Github external
'use strict';

const Subscription = require('egg').Subscription;

class AllInterval extends Subscription {
  async subscribe() {
    this.ctx.logger.info('all&&interval');
  }

  static get schedule() {
    return {
      interval: 3000,
      type: 'all',
    };
  }
}

module.exports = AllInterval;