Pomelo adds scheduled tasks and pomelo adds tasks
Requirement: Add a rank scheduled task under the arena server to rank players every minute.
First, add the cron directory under the game-server/app/servers/arena directory,
In the game-server/app/servers/arena/cron directory, write the code rankCron. js for the specific task to be executed. For example:
var utils = require('../../../util/utils');module.exports = function(app) { return new Cron(app);};var Cron = function(app) { this.app = app;};Cron.prototype.rank = function() { utils.show('arena rank');};
Then add the crons. json configuration file for the scheduled task in the game-server/config/directory. The specific configuration file is as follows:
{ "development":{ "arena": [ {"id": 1, "time": "0 0/1 * * * *", "action": "rankCron.rank"} ] }, "production":{ "arena": [ {"id": 1, "time": "0 0/1 * * * *", "action": "rankCron.rank"} ] }}
Result
In the configuration file crons. json, id is the unique identifier of a scheduled task on a specific server and cannot be repeated on the same server;
Time is the specific time for scheduled task execution. The definition of time is similar to that of linux scheduled task. There are seven fields in total. The specific definition of each field is as follows:
* * * * * * command to be executed- - - - - -| | | | | || | | | | +----- day of week (0 - 6) (Sunday=0)| | | | +------- month (0 - 11)| | | +--------- day of month (1 - 31)| | +----------- hour (0 - 23)| +------------- min (0 - 59)+------------- second (0 - 59)
For example, "0 30 10 ***" means that the corresponding task is executed at every day. "0 0/1 ***" means that the corresponding task is executed every minute.
ServerId is an optional field. If this field is set, the task is executed only on the server. If this field is not set, the scheduled task is executed on all servers of the same type;
Action is the specific method of executing the task. chatCron. sendMoney indicates that the sendMoney method in game-server/app/servers/chat/cron/chatCron. js is executed.
Appendix: linux scheduled task
Use crontab-e to add the command to be executed
Format:
* ***/Path of the command to be executed
The first five fields are represented respectively:
Minute: 0-59
Hours: 1-23
Date: 1-31
Month: 1-12
Week: 0-6 (0 indicates Sunday)
You can also use some special symbols:
*: Indicates any time
,: Indicates Segmentation
-: Indicates a segment. For example, 1-5 in the second end indicates.
/N: indicates that each n is executed once. For example, in the second segment, */1 indicates that the command is executed every one hour. You can also enter 1-23/1.
Use */1 in pomelo to report an error. Change it to 0/1.