Skip to content
This repository was archived by the owner on Sep 25, 2023. It is now read-only.

Pomelo's new features in version 0.7

py edited this page Nov 5, 2013 · 7 revisions

New features in Pomelo 0.7

In pomelo 0.7, we add crontab feature and developers could add or remove crontab dynamically in different servers; On the advice of the developers, we introduce global filter and this allow developers uniformly handle messages in frontend servers; in addition, in new edition we introduce simple transaction method, which includes conditions and handlers; others feature includes auto-complete of pomelo-cli.

Crontab

Developers can define crontabs through configuration file game-server/config/crons.json, also can add or remove crons by commands provided in pomelo-cli. Crontab in pomelo aims at servers, for example if you want to add crontab in chat server:

Firstly, you need to add cron directory in game-server/app/servers/chat/, then you can put your crontab code like chatCron.js in game-server/app/servers/chat/cron, for example:

module.exports = function(app) {
  return new Cron(app);
};
var Cron = function(app) {
  this.app = app;
};
var cron = Cron.prototype;

cron.sendMoney = function() {
  console.log('%s server is sending money now!', this.app.serverId);
};

Then you can add crontab configuration file crons.json in game-server/config/, the example code is as follows:

{
   "development":{
        "chat":[
             {"id":1, "time": "0 30 10 * * *", "action": "chatCron.sendMoney"},
             {"id":2, "serverId":"chat-server-1", "time": "0 30 10 * * *", "action": "chatCron.sendMoney"}
        ]
    },
    "production":{
        "chat":[
             {"id":1, "time": "0 30 10 * * *", "action": "chatCron.sendMoney"},
             {"id":2, "serverId":"chat-server-1", "time": "0 30 10 * * *", "action": "chatCron.sendMoney"}
        ]
  }
}

In crontab configuration file, id is the unique identification in crontab, and it can not be duplicated in the same server; time is the time when the crontab is executed, and which is like the time defined in linux crontab. And the definition of its 7 fields are as follows:

*     *     *     *   *    *        command to be executed
-     -     -     -   -    -
|     |     |     |   |    |
|     |     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |     |   +------- month (1 - 12)
|     |     |     +--------- day of month (1 - 31)
|     |     +----------- hour (0 - 23)
|     +------------- min (0 - 59)
+------------- second (0 - 59)

0 30 10 * * * means crontab is executed at 10:30 every day; serverId is an optional field, if you define this field, the crontab is

Global filter

Transaction

Auto-complete of pomelo-cli

In newest edition of pomelo-cli, we provide command auto-complete functionality.

Clone this wiki locally