Pomelo adds scheduled tasks and pomelo adds tasks

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.