{"id":20614008,"url":"https://github.com/evanpatchouli/evanpatchouli-scheduler","last_synced_at":"2025-07-05T02:34:26.479Z","repository":{"id":153899903,"uuid":"631044325","full_name":"Evanpatchouli/evanpatchouli-scheduler","owner":"Evanpatchouli","description":"A package help to manage the transcations scheduled in node.js","archived":false,"fork":false,"pushed_at":"2023-07-22T06:19:00.000Z","size":49,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-16T18:15:00.997Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"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/Evanpatchouli.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-21T19:27:20.000Z","updated_at":"2023-07-22T06:19:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"586a0dc9-65be-4a74-a8ec-4201b2b7fb4d","html_url":"https://github.com/Evanpatchouli/evanpatchouli-scheduler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Evanpatchouli/evanpatchouli-scheduler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evanpatchouli%2Fevanpatchouli-scheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evanpatchouli%2Fevanpatchouli-scheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evanpatchouli%2Fevanpatchouli-scheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evanpatchouli%2Fevanpatchouli-scheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Evanpatchouli","download_url":"https://codeload.github.com/Evanpatchouli/evanpatchouli-scheduler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evanpatchouli%2Fevanpatchouli-scheduler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263671788,"owners_count":23494040,"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-16T11:11:38.088Z","updated_at":"2025-07-05T02:34:26.464Z","avatar_url":"https://github.com/Evanpatchouli.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @evanpatchouli/scheduler\nA package help to manage the transcations scheduled in node.js.  \nThis frame is based on **node-schedule**,which thanks for the grate work the team of.\n\n## Install\n\n```shell\nnpm install @evanpatchouli/scheduler\n```\n\n## Latest Version\n\n**v1.1.3**:\n- Fix 1 bug and improve doc.\n\n**v1.1.2**:\n- Refactored by TypeScript.\n\n**v1.1.1**:\n- **Task.LogOn**: You can deside whether the task need to log.\n- **Task.cacheOn**: You can deside whethre the task need to store histories in memory.\n- **Plan** class: you can bind a group of task into a plan, by manage its tasks by plan\n- **PlanTool** module: a tool to manage the plans in plan pool  \n- **ScheTool** module: a tool to help use Scheduler easier.\n\n**v1.1.0**:\n- Since this version, the class Job and JobHelper have been refactored to Task and TaskHelper.\n- Besides, there is a new mechanism with a new class Plan, where you can put several related Tasks into it. Altought it is in development so it is of useless at this version, but it will works at next version.\n- Fix 1 bug in JobHelper(now named TaskHelper).\n\n## Documentation\n\n- [Task](#task)\n- [Plan](#plan)\n- [PlanTool](#plantool)\n- [Scheduler](#scheduler)\n- [ScheTool](#schetool)\n- [TaskHelper](#taskhelper)\n- [Starter](#starter)\n- [Warning](#warnning)\n\n## Task\n\n```js\nconst { Task } = require(\"@evanpatchouli/scheduler\");\n```\n\n### create a Task\n\nBy Task constructor, you should give 4 params:\n- name : Task name\n- rule : the rule which Task is scheduled by, and it's same as the rule in \"node-schedule\"\n- todo : the things Task going to do\n```js\nconst task = new Task(\"HelloTask\", \"* * * * * *\", ()=\u003e{\n    console.log(\"Hello, there is Scheduler\");\n})\n```\n- options : it can contain `logOn` and `cacheOn`\n```js\nconst task = new Task(\"HelloTask\", \"* * * * * *\", ()=\u003e{\n    console.log(\"Hello, there is Scheduler\", {logOn: false, cacheOn:false});\n})\n```\nIf you don't give the options of options only have all attributes, true will be default logOn and false will be default cacheOn.  \nLook at the following example, this task.logOn will be true and its cacheOn will be false.\n```js\nconst task = new Task(\"HelloTask\", \"* * * * * *\", ()=\u003e{\n    console.log(\"Hello, there is Scheduler\", {cacheOn:false});\n})\n```\n\nAlthough Task has many other methods, please do not use them directly by Task. You should use **Scheduler** or **Plan** or **PlanTool** or **ScheTool** to manage your tasks unless you want to manage tasks yourself without Scheduler.\n\n## Plan\n\nYou can put a group of task into a plan and manage them by plan. Before you really start a plan, you **must** use **PlanTool.addPlan** to add this plan into Scheduler.plan_pool.\n```js\nconst { Plan } = require('@evanpatchouli/scheduler');\n```\n\n### create a plan\n\nCreate a plan without tasks\n```js\nlet plan = new Plan(\"plan1\");\n```\n\nCreate a plan with unstarted tasks\n```js\nlet plan = new Plan(\"plan1\",[task1,task2]);\n```\n\n### add a task into a plan\n\nthe param should be of Task\n```js\nplan.addTask(task1);\n```\n\n### add tasks into a plan\n\n```js\nplan.addTasks([task1,task2]);\n```\n\n### get a task from a plan\n\n```js\nPlan.getTask(\"task1\");\n```\n\n### remove a task from a plan\n\nthe param could be of Task or Task.name\n```js\nplan.removeTask(task1);\nplan.removeTask(\"task1\");   //\"task1\" is the name of task1\n```\n\n### remove tasks from a plan\n```js\nplan.removeTasks([task1,task2]);\n```\n\n### start\n\nStart all tasks of this plan\n```js\nplan.start();\n```\n\n### Stop\n\nStop all tasks of this plan\n```js\nplan.stop();\n```\n\n### startTask\n\nOnly start one certain task in plan.The task could be Task.name or Task\n```js\nplan.startTask(task1);\n```\n\n### startTasks\n\nOnly start some tasks in plan\n```js\nplan.startTasks([task1,\"task2\"]);\n```\n\n### stopTask\n\nOnly stop one certain task in plan.The task could be Task.name or Task\n```js\nplan.stopTask(task1);\n```\n\n### stopTasks\n\nOnly stop some tasks in plan\n```js\nplan.stopTasks([task1,\"task2\"]);\n```\n\n### restart\n\nStop all tasks in this plan and restart them.\n```js\nplan.restart();\n```\n\n### restartTask\n\nOnly restart one certain task in plan.The task could be Task.name or Task\n```js\nplan.startTask(task1);\n```\n\n### restartTasks\n\nOnly start some tasks in plan\n```js\nplan.startTasks([task1,\"task2\"]);\n```\n\n### rescheduleTask\n\nRestart one certain task in plan. The usage is similar to **Scheduler.rescheduleTask**\n```js\nplan.startTask(task1,\"* * * * * *\");\n```\n\n## PlanTool\n\nA module to manage your plans.\n```js\nconst { PlanTool } = require('@evanpatchouli/scheduler');\n```\n\n### addPlan\nBefore you really start a plan, you **must** use **PlanTool.addPlan** to add this plan into Scheduler.plan_pool.\n```js\nPlanTool.addPlan(plan);\n```\n\n### startPlan\nStop a plan though PlanTool, the param chould be name or Plan\n```js\nPlanTool.startPlan(plan);\n```\n\n### stopPlan\nStop a plan though PlanTool, the param chould be name or Plan\n```js\nPlanTool.stopPlan(plan);\n```\n\n### removePlan\nStop and remove a plan though PlanTool, the param chould be name or Plan\n```js\nPlanTool.removePlan(plan);\n```\n\n### dumpPlans\nStop and remove all plans though PlanTool\n```js\nPlanTool.dumpPlans();\n```\n\n### findPlan\nYou can get the Plan object by its name\n```js\nlet plan1 = PlanTool.findPlan(\"plan1\");\n```\n\n## Scheduler\n\n```js\nconst { Scheduler } = require(\"@evanpatchouli/scheduler\");\n```\n\nThe manager, a singleton, for you to manage your tasks like add, start, stop, restart, remove...\n\n### getInstance\n```js\nlet scheduler = Scheduler.getInstance();\n```\n\n### addTask\n\nAdd a new task into task pool, the name of task **must be unique and does not ends with \"-helper\"**\n```js\nconst task = new Task(\"HelloTask\", \"* * * * * *\", ()=\u003e{\n    console.log(\"Hello, there is Scheduler\");\n})\nscheduler.addTask(task);\n```\nIt is just be add into task pool without being started. If you want to start the task as soon as it is added, do like this:\n```js\nscheduler.addTask(task, true);\n```\n\n### addTasks\n\nYou can use **addTasks** to add a series of Tasks into task pool\n```js\nconst task1 = new Task(\"HelloTask1\", \"* * * * * *\", ()=\u003e{\n    console.log(\"Hello, there is Scheduler\");\n})\nconst task2 = new Task(\"HelloTask2\", \"* * * * * *\", ()=\u003e{\n    console.log(\"Hello, there is Scheduler\");\n})\nscheduler.addTasks([task1,task2]);\n```\nYou can also give the second param as true to make all of them to start at once.  \nIn future, this method may support to appoint every task whether to start or not.\n\n### getTask\n\n```js\nscheduler.getTask(\"task1\");\n```\n\n### startTask\n\nIf a task is not running(hasn't been started or has been stoped), use startTask can start it at once.\n```js\nscheduler.start(\"HelloTask\");\n```\nOr\n```js\nconst task = new Task(\"HelloTask\", \"* * * * * *\", ()=\u003e{\n    console.log(\"Hello, there is Scheduler\");\n})\nscheduler.start(task);\n```\nBoth name and Task are allowed.\n\n### startTasks\n\nA method to start a series of tasks at once, and both Array of name and Task are allowed.\n\n### startAll\n\nA method to start all tasks in task pool.\n\n### stopTask\n\nA method to stop a task schedule, and its usage is similar to addTask.\n\n### stopTasks\n\nA method to stop a series of tasks schedule, and its usage is similar to addTasks.\n\n### stopAll\n\nA method to stop all tasks in task pool.\n\n### removeTask\n\nA method to remove a task from pool, and its usage is similar to addTask. If the task is alive, it will be canceld first by Scheduler and then be removed.\n\n### removeTasks\n\nA method to remove a series of tasks, and its usage is similar to addTasks.\n\n### restartTask\n\nA method to restart a task, and its usage is similar to addTask.\n\n### restartTasks\n\nA method to restart a series of tasks schedule, and its usage is similar to addTasks.\n\n### rescheduleTask\n\nA method to reschedule a task(Only reset rule, will not reset todo).  \nYou can use it like:\n```js\nscheduler.rescheduleTask(\"HelloTask\",\"*\\5 * * * * *\");\n```\nOr\n```js\nconst task = new Task(\"HelloTask\", \"*\\5 * * * * *\", ()=\u003e{})\nscheduler.rescheduleTask(task);\n```\nOr\n```js\nconst task = new Task(\"HelloTask\", \"*\\5 * * * * *\", ()=\u003e{})\nscheduler.rescheduleTask({task: task});\n```\nOr\n```js\nconst task = new Task(\"HelloTask\", \"* * * * * *\", ()=\u003e{})\nscheduler.rescheduleTask({task: task, rule: \"*\\5 * * * * *\"});\n```\nOr\n```js\nscheduler.rescheduleTask({task: \"HelloTask\", rule: \"* * * * * *\"});\n```\nWhen you both give task\u003cTask\u003e and rule ( rescheduleTask({task,rule}) or rescheduleTask(task,rule) ), if rule is null or undefind, Scheduler will use task.rule to reschedule it.\n### rescheduleTasks\n\n(Unaccomplished) A method to reschedule a series of tasks schedule.\n\n## ScheTool\n\n```js\nconst { ScheTool } = require('@evanpatchouli/scheduler');\n```\n\n### dumpTaskPool\nRemove all tasks without care about dumpPlans\n```js\nScheTool.dumpTaskPool();\n```\n\n## TaskHelper\n\nEvery task added into pool, Scheduler will auto rigister an one-to-one Task named `${task.name}-helper` to help manage this task, release cache regularly...  \nAnd TaskHelper's logOn and cacheOn will be same with the task it helps.\n\n## Starter\n\n```js\nconst { Starter } = require(\"@evanpatchouli/scheduler\");\n```\n\nA module provides packaged functions to init and start Scheduler and it can print `Scheduler` Logo in consle at fitst time.\n\n### run\n\nStarter.run(isLogo, todo, params):\n- isLogo : whether to ptint `Scheduler` Logo, if you don't want to print Logo, you can give `false` or not give any param.\n- a function packaged with the things you want to do\n- if todo needs params, please make them to `k-v` object\n\nExample\n```js\nlet params = {\n    plan,task1,task2\n}\nStarter.run(true, todo, params);\nfunction todo(params) {\n    setTimeout(()=\u003e{PlanTool.startPlan(params.plan);},5000);\n    setTimeout(()=\u003e{Scheduler.stopAll();},20000);\n}\n```\n\n### !Warnning\nif you start task or plan in todo,must avoid to do actions of start/stop... by Scheduler/PlanTool/ScheTool at once, because js is single thread, if you have to do, please use setTimeout to create enough time delay between Starter and your outer star/stop/dump action code.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevanpatchouli%2Fevanpatchouli-scheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevanpatchouli%2Fevanpatchouli-scheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevanpatchouli%2Fevanpatchouli-scheduler/lists"}