{"id":20572026,"url":"https://github.com/netease/pomelo-scheduler","last_synced_at":"2025-04-14T17:08:14.257Z","repository":{"id":5571147,"uuid":"6776736","full_name":"NetEase/pomelo-scheduler","owner":"NetEase","description":"the high performance schedule module for calling scheduled task","archived":false,"fork":false,"pushed_at":"2018-01-30T02:19:04.000Z","size":413,"stargazers_count":49,"open_issues_count":2,"forks_count":47,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-14T17:08:01.350Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NetEase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-20T11:20:05.000Z","updated_at":"2025-03-07T11:31:00.000Z","dependencies_parsed_at":"2022-07-06T14:31:30.739Z","dependency_job_id":null,"html_url":"https://github.com/NetEase/pomelo-scheduler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetEase%2Fpomelo-scheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetEase%2Fpomelo-scheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetEase%2Fpomelo-scheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetEase%2Fpomelo-scheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NetEase","download_url":"https://codeload.github.com/NetEase/pomelo-scheduler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923764,"owners_count":21183953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T05:18:04.745Z","updated_at":"2025-04-14T17:08:14.236Z","avatar_url":"https://github.com/NetEase.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pomelo-scheduler\npomelo-schedule is a schedule tool for nodejs, it's purpose is to provide a product level schedule module which is high efficient and can support large number job schedule.You can \n\nAs a schedule tool, it support two kinds of trigger: A simple trigger which use a js object and  a Cron time trigger which use a Cron time string.\n##Installation\n```\nnpm install pomelo-schedule\n```\n##Schedule simple Job\nSimple job will receive a object as a trigger, which take three attributes, a JS function as object, and an object as the parameters in the job.\n\n###Simple trigge example\n``` javascript\n//Fire 10000ms after now, and run 10 times with a 1000ms interval.\nvar trigger1 = {\n  start : Date.now() + 10000, //Start time, use the time in date object\n  period : 1000,      //Fire interval, the precision is millisecond\n  count : 10          //Fire times, in this case the trigger will fire 10 times.   \n}\n\n//Fire right now, and run 10 times with 1000ms interval.\nvar trigger2 = {\n  period : 1000,\n  count : 10\n}\n\n//Fire right now, and run for ever with 1000ms interval.\nvar trigger3 = {\n  period : 1000\n}\n\n//Fire 3000ms after right now, run only once.\nvar trigger4 = {\n  start : Date.now() + 3000;\n}\n\n//The job will fire right now, run only once.\nvar trigger5 = {\n}\n\n//Illegal! The 'count' attribute cannot used alone without 'period'.  \nvar trigger6 = {\n  count : 10;\n}\n``` \n\n###Simple job example\n``` javascript\nvar schedule = require('../lib/schedule');\n\nvar simpleJob = function(data){\n   console.log(\"run Job :\" + data.name);\n}\n\nschedule.scheduleJob({start:Date.now(), period:3000, count: 10}, simpleJob, {name: 'simpleJobExample'});\n```\n##Schedule cron Job\nCron job is the job that use cron trigger, it is just like the simple job, only use the cron trigger instead of simple trigger.\n\n###Cron job example\n``` javascript\nvar schedule = require('../lib/schedule');\n\nvar cronJob = function(data){\n   console.log(\"run Job :\" + data.name);\n}\n\nschedule.scheduleJob(\"0 0/15 8 * * *\", cronJob, {name:'cronJobExample'});\n```\n###Cron Trigger syntax\nCron trigger has 7 fiels, the format is very like the cronTab in linux, only add a second field in the head. The fields and the boundary is as follow:\n\u003cpre style=\"bgcolor='#dbdbdb'\"\u003e\n*     *     *     *   *    *        command to be executed\n-     -     -     -   -    -\n|     |     |     |   |    |\n|     |     |     |   |    +----- day of week (0 - 6) (Sunday=0)\n|     |     |     |   +------- month (1 - 12)\n|     |     |     +--------- day of month (1 - 31)\n|     |     +----------- hour (0 - 23)\n|     +------------- min (0 - 59)\n+------------- second (0 - 59)\n\u003c/pre\u003e\n###Exampe of cron tirggers\n\n\"0/2 0 8 * * 6\"    Fire at every Satuaday at every even seconds of 08:00\n\"0 30 10 1 4 *\"      Fire at 10:30 on 1st of March  \n\"15 15 15 10 10 *\"   Fire at Octorber 10th, at 15:15:15.\n\n###Special characters\nPomelo-schedule allow three kinds of spechial characters, they are '-', '/' and '.'.\n\n-: '-' means range. For example, 1-3 in the second field means the seconds 1, 2 and 3\n\n/: means increasement. For exapmle, 1/20 in the second field means 1, 21 and 41 second, and 1/2 means for every odd seconds as 1, 3, 5 ... ...\n\n,: means additional values. For example, 1, 10, 15 in the second field means 1, 10 and 15 second. You can use '-', and '/' with ',', for example, 11,20-22,0/2 in the second filed means 11, 21 and all the even seconds. \n\n##Cancel Job \n``` javascript\nvar schedule = require('../lib/schedule');\n\nvar simpleJob = function(){\n   console.log(\"run simple Job \");\n}\n\n//Add a simple job and save the id \nvar id = schedule.scheduleJob({period: 1000}, simpleJob, {});\n\n/**\n * Do some thing else\n */\n\n//CancelJob\nschedule.cancelJob(id);\n```\nWhen you cancel a job, it will stop schedule immidiatelly, and delete the job.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetease%2Fpomelo-scheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetease%2Fpomelo-scheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetease%2Fpomelo-scheduler/lists"}