agenda-ts 1.6.9-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +353 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/job/compute-next-run-at.d.ts +3 -0
- package/dist/job/compute-next-run-at.js +114 -0
- package/dist/job/compute-next-run-at.js.map +1 -0
- package/dist/job/disable.d.ts +3 -0
- package/dist/job/disable.js +9 -0
- package/dist/job/disable.js.map +1 -0
- package/dist/job/enable.d.ts +3 -0
- package/dist/job/enable.js +9 -0
- package/dist/job/enable.js.map +1 -0
- package/dist/job/fail.d.ts +3 -0
- package/dist/job/fail.js +28 -0
- package/dist/job/fail.js.map +1 -0
- package/dist/job/fetch-status.d.ts +10 -0
- package/dist/job/fetch-status.js +23 -0
- package/dist/job/fetch-status.js.map +1 -0
- package/dist/job/index.d.ts +89 -0
- package/dist/job/index.js +109 -0
- package/dist/job/index.js.map +1 -0
- package/dist/job/is-expired.d.ts +2 -0
- package/dist/job/is-expired.js +16 -0
- package/dist/job/is-expired.js.map +1 -0
- package/dist/job/is-running.d.ts +2 -0
- package/dist/job/is-running.js +21 -0
- package/dist/job/is-running.js.map +1 -0
- package/dist/job/priority.d.ts +3 -0
- package/dist/job/priority.js +10 -0
- package/dist/job/priority.js.map +1 -0
- package/dist/job/remove.d.ts +2 -0
- package/dist/job/remove.js +8 -0
- package/dist/job/remove.js.map +1 -0
- package/dist/job/repeat-at.d.ts +3 -0
- package/dist/job/repeat-at.js +9 -0
- package/dist/job/repeat-at.js.map +1 -0
- package/dist/job/repeat-every.d.ts +10 -0
- package/dist/job/repeat-every.js +21 -0
- package/dist/job/repeat-every.js.map +1 -0
- package/dist/job/run.d.ts +3 -0
- package/dist/job/run.js +92 -0
- package/dist/job/run.js.map +1 -0
- package/dist/job/save.d.ts +3 -0
- package/dist/job/save.js +8 -0
- package/dist/job/save.js.map +1 -0
- package/dist/job/schedule.d.ts +3 -0
- package/dist/job/schedule.js +12 -0
- package/dist/job/schedule.js.map +1 -0
- package/dist/job/set-shouldsaveresult.d.ts +3 -0
- package/dist/job/set-shouldsaveresult.js +9 -0
- package/dist/job/set-shouldsaveresult.js.map +1 -0
- package/dist/job/to-json.d.ts +3 -0
- package/dist/job/to-json.js +21 -0
- package/dist/job/to-json.js.map +1 -0
- package/dist/job/touch.d.ts +3 -0
- package/dist/job/touch.js +14 -0
- package/dist/job/touch.js.map +1 -0
- package/dist/job/unique.d.ts +6 -0
- package/dist/job/unique.js +10 -0
- package/dist/job/unique.js.map +1 -0
- package/dist/pulse/cancel.d.ts +3 -0
- package/dist/pulse/cancel.js +21 -0
- package/dist/pulse/cancel.js.map +1 -0
- package/dist/pulse/close.d.ts +5 -0
- package/dist/pulse/close.js +25 -0
- package/dist/pulse/close.js.map +1 -0
- package/dist/pulse/count-jobs.d.ts +5 -0
- package/dist/pulse/count-jobs.js +12 -0
- package/dist/pulse/count-jobs.js.map +1 -0
- package/dist/pulse/create.d.ts +3 -0
- package/dist/pulse/create.js +31 -0
- package/dist/pulse/create.js.map +1 -0
- package/dist/pulse/database.d.ts +4 -0
- package/dist/pulse/database.js +33 -0
- package/dist/pulse/database.js.map +1 -0
- package/dist/pulse/db-init.d.ts +3 -0
- package/dist/pulse/db-init.js +34 -0
- package/dist/pulse/db-init.js.map +1 -0
- package/dist/pulse/default-concurrency.d.ts +3 -0
- package/dist/pulse/default-concurrency.js +13 -0
- package/dist/pulse/default-concurrency.js.map +1 -0
- package/dist/pulse/default-lock-lifetime.d.ts +3 -0
- package/dist/pulse/default-lock-lifetime.js +13 -0
- package/dist/pulse/default-lock-lifetime.js.map +1 -0
- package/dist/pulse/default-lock-limit.d.ts +3 -0
- package/dist/pulse/default-lock-limit.js +13 -0
- package/dist/pulse/default-lock-limit.js.map +1 -0
- package/dist/pulse/define.d.ts +23 -0
- package/dist/pulse/define.js +34 -0
- package/dist/pulse/define.js.map +1 -0
- package/dist/pulse/disable.d.ts +3 -0
- package/dist/pulse/disable.js +22 -0
- package/dist/pulse/disable.js.map +1 -0
- package/dist/pulse/drain.d.ts +2 -0
- package/dist/pulse/drain.js +26 -0
- package/dist/pulse/drain.js.map +1 -0
- package/dist/pulse/enable.d.ts +3 -0
- package/dist/pulse/enable.js +22 -0
- package/dist/pulse/enable.js.map +1 -0
- package/dist/pulse/every.d.ts +4 -0
- package/dist/pulse/every.js +37 -0
- package/dist/pulse/every.js.map +1 -0
- package/dist/pulse/find-and-lock-next-job.d.ts +3 -0
- package/dist/pulse/find-and-lock-next-job.js +43 -0
- package/dist/pulse/find-and-lock-next-job.js.map +1 -0
- package/dist/pulse/has-mongo-protocol.d.ts +1 -0
- package/dist/pulse/has-mongo-protocol.js +8 -0
- package/dist/pulse/has-mongo-protocol.js.map +1 -0
- package/dist/pulse/index.d.ts +115 -0
- package/dist/pulse/index.js +208 -0
- package/dist/pulse/index.js.map +1 -0
- package/dist/pulse/job-processing-queue.d.ts +11 -0
- package/dist/pulse/job-processing-queue.js +51 -0
- package/dist/pulse/job-processing-queue.js.map +1 -0
- package/dist/pulse/jobs.d.ts +6 -0
- package/dist/pulse/jobs.js +14 -0
- package/dist/pulse/jobs.js.map +1 -0
- package/dist/pulse/lock-limit.d.ts +3 -0
- package/dist/pulse/lock-limit.js +13 -0
- package/dist/pulse/lock-limit.js.map +1 -0
- package/dist/pulse/max-concurrency.d.ts +3 -0
- package/dist/pulse/max-concurrency.js +13 -0
- package/dist/pulse/max-concurrency.js.map +1 -0
- package/dist/pulse/mongo.d.ts +4 -0
- package/dist/pulse/mongo.js +10 -0
- package/dist/pulse/mongo.js.map +1 -0
- package/dist/pulse/name.d.ts +3 -0
- package/dist/pulse/name.js +13 -0
- package/dist/pulse/name.js.map +1 -0
- package/dist/pulse/now.d.ts +3 -0
- package/dist/pulse/now.js +21 -0
- package/dist/pulse/now.js.map +1 -0
- package/dist/pulse/process-every.d.ts +3 -0
- package/dist/pulse/process-every.js +14 -0
- package/dist/pulse/process-every.js.map +1 -0
- package/dist/pulse/purge.d.ts +2 -0
- package/dist/pulse/purge.js +13 -0
- package/dist/pulse/purge.js.map +1 -0
- package/dist/pulse/resume-on-restart.d.ts +3 -0
- package/dist/pulse/resume-on-restart.js +39 -0
- package/dist/pulse/resume-on-restart.js.map +1 -0
- package/dist/pulse/save-job.d.ts +4 -0
- package/dist/pulse/save-job.js +104 -0
- package/dist/pulse/save-job.js.map +1 -0
- package/dist/pulse/schedule.d.ts +4 -0
- package/dist/pulse/schedule.js +36 -0
- package/dist/pulse/schedule.js.map +1 -0
- package/dist/pulse/sort.d.ts +3 -0
- package/dist/pulse/sort.js +13 -0
- package/dist/pulse/sort.js.map +1 -0
- package/dist/pulse/start.d.ts +2 -0
- package/dist/pulse/start.js +19 -0
- package/dist/pulse/start.js.map +1 -0
- package/dist/pulse/stop.d.ts +2 -0
- package/dist/pulse/stop.js +38 -0
- package/dist/pulse/stop.js.map +1 -0
- package/dist/utils/create-job.d.ts +3 -0
- package/dist/utils/create-job.js +10 -0
- package/dist/utils/create-job.js.map +1 -0
- package/dist/utils/error.d.ts +12 -0
- package/dist/utils/error.js +34 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/parse-priority.d.ts +1 -0
- package/dist/utils/parse-priority.js +31 -0
- package/dist/utils/parse-priority.js.map +1 -0
- package/dist/utils/process-jobs.d.ts +3 -0
- package/dist/utils/process-jobs.js +203 -0
- package/dist/utils/process-jobs.js.map +1 -0
- package/package.json +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mohamed Meabed <mo.meabed@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./pulse.png" width="100" alt="project-logo">
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<h1 align="center">AGENDA-TS</h1>
|
|
6
|
+
</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<em>The modern MongoDB-powered job scheduler library for Node.js</em>
|
|
9
|
+
</p>
|
|
10
|
+
<p align="center">
|
|
11
|
+
<img src="https://img.shields.io/github/license/meabed/agenda-ts?style=default&logo=opensourceinitiative&logoColor=white&color=24E0A4" alt="license">
|
|
12
|
+
<img src="https://img.shields.io/github/last-commit/meabed/agenda-ts?style=default&logo=git&logoColor=white&color=24E0A4" alt="last-commit">
|
|
13
|
+
<img src="https://img.shields.io/github/languages/top/meabed/agenda-ts?style=default&color=24E0A4" alt="repo-top-language">
|
|
14
|
+
<img src="https://img.shields.io/github/languages/count/meabed/agenda-ts?style=default&color=24E0A4" alt="repo-language-count">
|
|
15
|
+
<p>
|
|
16
|
+
<p align="center">
|
|
17
|
+
<!-- default option, no dependency badges. -->
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<br><!-- TABLE OF CONTENTS -->
|
|
21
|
+
|
|
22
|
+
<p align="center">
|
|
23
|
+
<a href="https://github.com/meabed/agenda-ts">Documentation</a> | <a href="https://github.com/meabed/agenda-ts">Repository</a>
|
|
24
|
+
</p>
|
|
25
|
+
<details>
|
|
26
|
+
<summary>Table of Contents</summary><br>
|
|
27
|
+
|
|
28
|
+
- [Overview](#overview)
|
|
29
|
+
- [Related Projects](#related-projects)
|
|
30
|
+
- [Unique Features in Agenda-TS](#unique-features-in-agenda-ts)
|
|
31
|
+
- [Repository Structure](#repository-structure)
|
|
32
|
+
- [Modules](#modules)
|
|
33
|
+
- [Getting Started](#getting-started)
|
|
34
|
+
- [Installation](#installation)
|
|
35
|
+
- [Example](#example)
|
|
36
|
+
- [Project Roadmap](#project-roadmap)
|
|
37
|
+
- [Contributing](#contributing)
|
|
38
|
+
- [License](#license)
|
|
39
|
+
- [Acknowledgments](#acknowledgments)
|
|
40
|
+
</details>
|
|
41
|
+
<hr>
|
|
42
|
+
|
|
43
|
+
## Overview
|
|
44
|
+
|
|
45
|
+
Agenda-TS is a modern TypeScript fork of the [Agenda](https://github.com/agenda/agenda) project, created as the original project is no longer actively maintained. Positioned as a vital solution in the Node.js ecosystem for job scheduling, the hiatus of Agenda prompted the creation of Agenda-TS. Utilizing MongoDB, Agenda-TS introduces advanced functionalities, improved scalability, and contemporary features to address today's complex scheduling challenges.
|
|
46
|
+
|
|
47
|
+
<br/>
|
|
48
|
+
|
|
49
|
+
#### Related Projects
|
|
50
|
+
- [agenda-ts](https://github.com/meabed/agenda-ts) - Modern MongoDB-powered job scheduler for Node.js
|
|
51
|
+
- [nestjs-agenda-ts](https://github.com/meabed/nestjs-agenda-ts) - official NestJS module for Agenda-TS.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
<br/>
|
|
56
|
+
<br/>
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## Unique Features in Agenda-TS
|
|
60
|
+
|
|
61
|
+
- **Latest MongoDB Driver Support**: Agenda-TS is fully compatible with the latest MongoDB driver, ensuring users can take advantage of the most current database features and enhancements.
|
|
62
|
+
- **Resume Incomplete Tasks After System Restart**: When the system restarts, Agenda-TS resumes incomplete tasks that were in progress or queued for execution, providing seamless continuation without manual intervention.
|
|
63
|
+
- **Retry Failed Tasks**: Agenda-TS offers retry mechanisms using exponential and fixed backoff strategies with configurable attempts, ensuring efficient retries of failed tasks without overwhelming the system.
|
|
64
|
+
- **Continuous Maintenance**: As an open-source project actively maintained, Agenda-TS is consistently improved, providing users with reliable updates and support.
|
|
65
|
+
- **Extensive Documentation**: Provides detailed guides and examples for a quick and easy start.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
<br/>
|
|
69
|
+
<br/>
|
|
70
|
+
|
|
71
|
+
## Repository Structure
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
└── agenda-ts/
|
|
75
|
+
├── LICENSE
|
|
76
|
+
├── README.md
|
|
77
|
+
├── es.js
|
|
78
|
+
├── examples
|
|
79
|
+
│ └── concurrency.ts
|
|
80
|
+
├── package-lock.json
|
|
81
|
+
├── package.json
|
|
82
|
+
├── src
|
|
83
|
+
│ ├── cjs.ts
|
|
84
|
+
│ ├── index.ts
|
|
85
|
+
│ ├── job
|
|
86
|
+
│ ├── pulse
|
|
87
|
+
│ └── utils
|
|
88
|
+
├── tsconfig.eslint.json
|
|
89
|
+
└── tsconfig.json
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
<br/>
|
|
94
|
+
<br/>
|
|
95
|
+
|
|
96
|
+
## Modules
|
|
97
|
+
|
|
98
|
+
<details closed><summary>src.pulse</summary>
|
|
99
|
+
|
|
100
|
+
| File | Summary |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| [has-mongo-protocol.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/has-mongo-protocol.ts) | HasMongoProtocol establishes a function that evaluates if a given URL string contains a valid MongoDB connection protocol, contributing to the repositorys ability to handle and verify database connections. |
|
|
103
|
+
| [default-concurrency.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/default-concurrency.ts) | Sets the default concurrency for each job within the Agendta-TS open-source project by modifying the internal state. It contributes to the task scheduling and management functionalities in the project. |
|
|
104
|
+
| [name.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/name.ts) | Sets the name of a queue within the Agendta object in the parent repositorys architecture. It utilizes debugging for traceability and maintains the flow architecture by returning the Agendta instance after the name assignment. |
|
|
105
|
+
| [drain.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/drain.ts) | Drain.ts serves a crucial role in the Agendta module, enabling the cancellation of ongoing job processes. It ensures that all running jobs get completed before terminating the processing interval, promoting an efficient and orderly execution flow in the application. |
|
|
106
|
+
| [enable.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/enable.ts) | Enables specific jobs within the Agendta module by toggling the disabled flag to false. Utilizes MongoDB queries to precisely select matching jobs, aspiring to enhance the flexibility and robustness of job execution. Returns the count of jobs successfully enabled, aiding in operational tracking. |
|
|
107
|
+
| [schedule.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/schedule.ts) | Schedule.ts within the Agenda directory facilitates job scheduling for specific timings. Through this module, users can assign an array of job names to be executed at a specified time, along with associated data. Multiple jobs can be created at once, enhancing the efficiency of task management in the repository. |
|
|
108
|
+
| [default-lock-lifetime.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/default-lock-lifetime.ts) | Establishes the default lock lifetime in an Agendta application. It allows setting the default lock time in milliseconds, providing flexibility in managing task execution timelines. This is a critical feature for handling concurrency control in Agendta's job processing system. |
|
|
109
|
+
| [db-init.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/db-init.ts) | Establishes and initializes the database collection for job management in the Agendta-TS open-source project. It also includes optional index creation functionality, providing efficient job searching within the database. Notifiers for success or errors make the process transparent and manageable. |
|
|
110
|
+
| [process-every.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/process-every.ts) | ProcessEvery sets a default interval for an Agendta objects processing time. It leverages human-readable time intervals to determine the frequency of certain operations within the agenda directory of the repository. This function returns the updated Agendta object. |
|
|
111
|
+
| [disable.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/disable.ts) | Disables selected jobs in the Agendta application by applying a MongoDB filter query. The function returns the number of successfully disabled job instances, providing enhanced control over task execution. |
|
|
112
|
+
| [jobs.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/jobs.ts) | Within the Agendta-TS repository, the jobs.ts script from the src/pulse directory performs a crucial task. It retrieves all jobs matching a certain query from a MongoDB collection, with options for sorting, limiting and skipping results, transforming these into job objects before returning. |
|
|
113
|
+
| [start.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/start.ts) | Start.ts initializes job processing for the Agendta module. It validates system readiness before periodically processing tasks using the processJobs method from the utils directory. The method ensures job execution regularity and guarantees uninterrupted operation, provided a database is set beforehand. |
|
|
114
|
+
| [every.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/every.ts) | Within the agendta directory, every.ts establishes a regular job execution framework. It enables job scheduling at specified intervals, handling singular and multiple job names. Pertinent debugging information for scheduled job processes is also provided by this module. |
|
|
115
|
+
| [max-concurrency.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/max-concurrency.ts) | MaxConcurrency controls job execution in the Agendta system by globally setting the maximum concurrency value, thereby optimizing task management. It directly interacts with the core Agendta framework, ensuring that job execution does not exceed the defined threshold, enhancing overall process efficiency. |
|
|
116
|
+
| [purge.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/purge.ts) | Purge.ts, within the agenda subdirectory, provides functionality to remove all jobs from the queue in the Agenda application. It exports an asynchronous function that cancels undefined jobs, ensuring only defined jobs remain. The function's outcome is confirmed with success or failure notifications. |
|
|
117
|
+
| [now.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/now.ts) | Establishes a function within the Agenda module, designed to create a job task instantly. This function, named now, accepts job details, schedules it for the current time, saves the job into the system, and handles potential creation errors. |
|
|
118
|
+
| [default-lock-limit.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/default-lock-limit.ts) | Defines the maximum number of locks per job type in the Agenda system. It establishes a default limit, with each instance adjustable per user needs. The limit optimizes concurrent task handling, enhancing overall application performance. |
|
|
119
|
+
| [stop.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/stop.ts) | Stop.ts within the Agenda sub-directory is responsible for terminating the process of job execution. It achieves this by unlocking jobs that were locked for processing, allowing them to be re-run or accessed, and by clearing the job execution interval, effectively stopping further job processing. |
|
|
120
|
+
| [database.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/database.ts) | Database.ts, located in the src/pulse directory, establishes a connection to a specified MongoDB server. It features the flexibility to use an existing MongoDB connection, customize collection names, and handle connection errors. Ultimately, this file integrates MongoDB into the broader Agenda architecture. |
|
|
121
|
+
| [sort.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/sort.ts) | Sort.ts orchestrates the sorting functionality within the Agenda component, allowing users to customize their queries for job searches. It primarily manages the rules for prioritizing and scheduling jobs, with the default being jobs sorted by their next run time and priority. |
|
|
122
|
+
| [mongo.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/mongo.ts) | Mongo.ts integrates MongoDB with the Agenda application, enabling the establishment of database connections. It provides a method to inject MongoClient instance, specify the collection, and handle database initialization errors through callbacks. |
|
|
123
|
+
| [cancel.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/cancel.ts) | Cancel.ts facilitates the termination of specific Agenda jobs based on a provided MongoDB query, effectively removing them from the database. These cancellations can be initiated by the client code, the Agenda.purge() function, or the Job.remove() function. |
|
|
124
|
+
| [index.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/index.ts) | Agenda, the heart of the repository, manages a queue of jobs in a MongoDB collection. This task scheduling system facilitates job creation, scheduling, locking, and execution, handling concurrency defaults, lock limits, and durations. Moreover, it supports optional configuration and customization parameters. |
|
|
125
|
+
| [define.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/define.ts) | Defines job parameters and execution procedures in the Agenda library. Users can configure concurrency, locking, priority, lifetime, and result persistence for a named job. Job definitions are stored and debugged for future execution within the Agendta system. |
|
|
126
|
+
| [create.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/create.ts) | Creates new jobs within the Agendta module of the repository. This piece of code initializes these jobs with given names and data, also setting specific attributes such as priority and whether to save results based on predefined definitions. |
|
|
127
|
+
| [find-and-lock-next-job.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/find-and-lock-next-job.ts) | Unlocks and processes queued jobs within the Agenda-TS repository. In the find-and-lock-next-job file, the function identifies a specific job based on its name, locks it for execution, and returns the job status. This operation ensures efficient management of tasks within the system. |
|
|
128
|
+
| [job-processing-queue.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/job-processing-queue.ts) | JobProcessingQueue, as part of the larger Agenda-TS repository, manages job processing through an internal queue. It offers capabilities like job insertion in a specific order, popping jobs without concurrency checks, and identifying the next job eligible for processing whose execution isnt blocked by concurrency. |
|
|
129
|
+
| [lock-limit.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/lock-limit.ts) | LockLimit sets a global upper limit on the number of jobs that can be simultaneously locked within the Agenda system, ensuring efficient task execution without resource overstretching. Its essential for maintaining concurrency control in the broader repository architecture. |
|
|
130
|
+
| [close.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/close.ts) | Agenda/close.ts secures the main functionality of closing database connections within the Agenda-TS project. It incorporates a provision for forcefully closing connections and handles exceptions that might arise during this process. The feature is specifically adapted for MongoDB databases that havent been preconfigured. |
|
|
131
|
+
| [save-job.ts](https://github.com/meabed/agenda-ts/blob/master/src/pulse/save-job.ts) | <code>► INSERT-TEXT-HERE</code> |
|
|
132
|
+
|
|
133
|
+
</details>
|
|
134
|
+
|
|
135
|
+
<details closed><summary>src.utils</summary>
|
|
136
|
+
|
|
137
|
+
| File | Summary |
|
|
138
|
+
| --- | --- |
|
|
139
|
+
| [parse-priority.ts](https://github.com/meabed/agenda-ts/blob/master/src/utils/parse-priority.ts) | ParsePriority, situated in the src/utils folder, transforms the priority of jobs from a textual format to a numerical representation. This allows the Agenda system within the repository to handle job scheduling based on priority levels, improving task queue management. |
|
|
140
|
+
| [process-jobs.ts](https://github.com/meabed/agenda-ts/blob/master/src/utils/process-jobs.ts) | <code>► INSERT-TEXT-HERE</code> |
|
|
141
|
+
| [create-job.ts](https://github.com/meabed/agenda-ts/blob/master/src/utils/create-job.ts) | CreateJob function, residing in src/utils/create-job.ts, orchestrates the generation of Job objects within the Agenda application. It complements the parent repositorys architecture by leveraging the Agenda instance and supplied job data to construct and return a Job. |
|
|
142
|
+
| [index.ts](https://github.com/meabed/agenda-ts/blob/master/src/utils/index.ts) | Facilitates job creation, priority parsing, and job processing, serving as a utility hub within the agenda repository. It critically interlinks these utility functions to streamline task organization and execution, enhancing the repository's overall functionality. |
|
|
143
|
+
|
|
144
|
+
</details>
|
|
145
|
+
|
|
146
|
+
<details closed><summary>src.job</summary>
|
|
147
|
+
|
|
148
|
+
| File | Summary |
|
|
149
|
+
| --- | --- |
|
|
150
|
+
| [enable.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/enable.ts) | Enable.ts activates a specific job type within the agenda project. By modifying an attribute in the Job object, it reverses the disabled status, allowing the job to run. This function integrates seamlessly with the wider repository structure, particularly the job module. |
|
|
151
|
+
| [is-running.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/is-running.ts) | Defines a function that determines if specific jobs within the application are currently running. It uses time comparisons, analyzing lastRunAt and lastFinishedAt properties, to deliver its verdict, thereby enhancing task management in the parent repository agenda. |
|
|
152
|
+
| [schedule.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/schedule.ts) | Schedule.ts in the job directory empowers a certain task to run at a predefined time. Using this feature, users can set either a specific date or a string pattern to determine the next execution instance of a job, thereby enhancing the scheduling capabilities in the overall Agenda project. |
|
|
153
|
+
| [touch.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/touch.ts) | Touch.ts within the job directory of the Agenda repository manages job concurrency. It updates a jobs lockedAt time, preventing multiple instances from running simultaneously. Can have an optional progress parameter (0-100). The function returns a Promise for the saved job. |
|
|
154
|
+
| [compute-next-run-at.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/compute-next-run-at.ts) | <code>► INSERT-TEXT-HERE</code> |
|
|
155
|
+
| [to-json.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/to-json.ts) | Transforms job details into a storable JSON object within the repositorys job management module. Converts key date attributes into the Date data type, facilitating data interchange with MongoDB. |
|
|
156
|
+
| [repeat-at.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/repeat-at.ts) | RepeatAt is a functionality of the Job module that arranges a task repetition at a specific interval. It accepts human-readable or numeric time variables, thereby empowering developers to schedule tasks dynamically within the agendta project. |
|
|
157
|
+
| [set-shouldsaveresult.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/set-shouldsaveresult.ts) | SetShouldSaveResult in the Job directory enables the persistence of a jobs return value by managing the relevant flag. It forms part of the repositorys core functionality, influencing how job results are stored and retrieved within the agendta system. |
|
|
158
|
+
| [disable.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/disable.ts) | Acting as a crucial component in the agendta repository, src/job/disable.ts provides the functionality to prevent specific jobs from running within the software system by modifying the job attributes. The solution enhances system control and ensures efficient resource allocation. |
|
|
159
|
+
| [fail.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/fail.ts) | Fail within the job directory of the Agenda repository ensures efficient error handling by marking a job as failed. It records the failure reason, increments the failure count, timestamps it, and debugs the number of times a job has failed, thereby improving transparency and traceability. |
|
|
160
|
+
| [priority.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/priority.ts) | In the context of the Agenda repository, priority.ts facilitates adjustment of task prioritization within the job queue. It leverages a method to parse and set job priority based on provided parameters, thereby influencing the order of job execution. |
|
|
161
|
+
| [remove.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/remove.ts) | In the context of the Agenda repository, remove.ts distresses a crucial function within the Job module. It facilitates the removal of a job from MongoDB by cancelling the job identified by its unique _id attribute. |
|
|
162
|
+
| [unique.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/unique.ts) | Within the broader Agenda repository, the unique.ts file fundamentally manages the uniqueness of a job. It contains a function that allows the creation of unique jobs by adding specific unique attributes and options to the job data. |
|
|
163
|
+
| [index.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/index.ts) | <code>► INSERT-TEXT-HERE</code> |
|
|
164
|
+
| [repeat-every.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/repeat-every.ts) | RepeatEvery, located within the job directory, enables task scheduling at regular intervals. It includes versatile options such as setting start dates, end dates, skipping specific days, and handling immediate execution scenarios, contributing significantly to the parent repository's task management capabilities. |
|
|
165
|
+
| [run.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/run.ts) | <code>► INSERT-TEXT-HERE</code> |
|
|
166
|
+
| [save.ts](https://github.com/meabed/agenda-ts/blob/master/src/job/save.ts) | Save.ts facilitates the persistence of job instances into MongoDB. Working within the job subdirectory of the agenda project, it enables asynchronous saving operations, either successfully storing a job or returning errors. |
|
|
167
|
+
|
|
168
|
+
</details>
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
<br/>
|
|
172
|
+
<br/>
|
|
173
|
+
|
|
174
|
+
## Getting Started
|
|
175
|
+
| Take a look at our [Quick Start](https://github.com/meabed/agenda-ts#example) guide.
|
|
176
|
+
|
|
177
|
+
#### Installation
|
|
178
|
+
|
|
179
|
+
```console
|
|
180
|
+
$ npm install --save agenda-ts
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
#### Example
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import Agenda from 'agenda-ts';
|
|
189
|
+
|
|
190
|
+
const mongoConnectionString = 'mongodb://localhost:27017/agenda';
|
|
191
|
+
|
|
192
|
+
const agenda = new Agenda({
|
|
193
|
+
db: { address: mongoConnectionString },
|
|
194
|
+
defaultConcurrency: 4,
|
|
195
|
+
maxConcurrency: 4,
|
|
196
|
+
processEvery: '10 seconds',
|
|
197
|
+
resumeOnRestart: true,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Or override the default collection name:
|
|
201
|
+
// const agenda = new Agenda({db: {address: mongoConnectionString, collection: 'jobCollectionName'}});
|
|
202
|
+
|
|
203
|
+
// or pass additional connection options:
|
|
204
|
+
// const agenda = new Agenda({db: {address: mongoConnectionString, collection: 'jobCollectionName', options: {ssl: true}}});
|
|
205
|
+
|
|
206
|
+
// or pass in an existing mongodb-native MongoClient instance
|
|
207
|
+
// const agenda = new Agenda({mongo: myMongoClient});
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Example of defining a job
|
|
211
|
+
*/
|
|
212
|
+
agenda.define('delete old users', async (job) => {
|
|
213
|
+
console.log('Deleting old users...');
|
|
214
|
+
return;
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Example of repeating a job
|
|
219
|
+
*/
|
|
220
|
+
(async function () {
|
|
221
|
+
// IIFE to give access to async/await
|
|
222
|
+
await agenda.start();
|
|
223
|
+
|
|
224
|
+
await agenda.every('3 minutes', 'delete old users');
|
|
225
|
+
|
|
226
|
+
// Alternatively, you could also do:
|
|
227
|
+
await agenda.every('*/3 * * * *', 'delete old users');
|
|
228
|
+
})();
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Example of defining a job with options
|
|
232
|
+
*/
|
|
233
|
+
pulse.define(
|
|
234
|
+
'send email report',
|
|
235
|
+
async (job) => {
|
|
236
|
+
const { to } = job.attrs.data;
|
|
237
|
+
|
|
238
|
+
console.log(`Sending email report to ${to}`);
|
|
239
|
+
},
|
|
240
|
+
{ lockLifetime: 5 * 1000, priority: 'high', concurrency: 10 }
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Example of scheduling a job
|
|
245
|
+
*/
|
|
246
|
+
(async function () {
|
|
247
|
+
await agenda.start();
|
|
248
|
+
await agenda.schedule('in 20 minutes', 'send email report', { to: 'admin@example.com' });;
|
|
249
|
+
})();
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Example of repeating a job
|
|
253
|
+
*/
|
|
254
|
+
(async function () {
|
|
255
|
+
const weeklyReport = agenda.create('send email report', { to: 'example@example.com' });
|
|
256
|
+
await agenda.start();
|
|
257
|
+
await weeklyReport.repeatEvery('1 week').save();
|
|
258
|
+
})();
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Check job start and completion/failure
|
|
262
|
+
*/
|
|
263
|
+
agenda.on('start', (job) => {
|
|
264
|
+
console.log(time(), `Job <${job.attrs.name}> starting`);
|
|
265
|
+
});
|
|
266
|
+
agenda.on('success', (job) => {
|
|
267
|
+
console.log(time(), `Job <${job.attrs.name}> succeeded`);
|
|
268
|
+
});
|
|
269
|
+
agenda.on('fail', (error, job) => {
|
|
270
|
+
console.log(time(), `Job <${job.attrs.name}> failed:`, error);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
function time() {
|
|
274
|
+
return new Date().toTimeString().split(' ')[0];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
<br/>
|
|
283
|
+
<br/>
|
|
284
|
+
|
|
285
|
+
## Project Roadmap
|
|
286
|
+
|
|
287
|
+
- [X] **Add Support for Latest Mongoose Version(8.x.x)**: Upgrade Agenda-TS to be fully compatible with the latest version of Mongoose. This will enable Agenda-TS to leverage the newest features and improvements in Mongoose, ensuring better performance, stability, and security for applications that rely on MongoDB through Mongoose.
|
|
288
|
+
- [X] **Refactoring to Modern TypeScript Syntax**: Undertake a comprehensive refactor of the codebase to utilize modern TypeScript features and syntax. This refactoring will improve code readability, maintainability, and make it easier for new contributors to understand and contribute to the project.
|
|
289
|
+
- [X] **Resolving Issues in Existing Agenda Projects**: Actively address and resolve outstanding issues within the original Agenda project. This initiative not only aids the community by improving the legacy codebase but also informs the development of Pulse by identifying and addressing past challenges.
|
|
290
|
+
- [ ] **Rewrite Test Code**: Revamp our testing suite to increase coverage and ensure tests are up-to-date with modern testing practices. This rewrite aims to enhance test reliability and efficiency, facilitating smoother development and deployment cycles.
|
|
291
|
+
- [X] **Rewrite Documentation**: Completely revise and update the documentation to reflect all new changes and features, ensure clarity of information, and improve navigation and readability for developers. This effort will include new getting started guides, API documentation, and use case examples to facilitate easier adoption and implementation by users.
|
|
292
|
+
---
|
|
293
|
+
<br/>
|
|
294
|
+
<br/>
|
|
295
|
+
|
|
296
|
+
## Contributing
|
|
297
|
+
|
|
298
|
+
Contributions are welcome! Here are several ways you can contribute:
|
|
299
|
+
|
|
300
|
+
- **[Report Issues](https://github.com/meabed/agenda-ts/issues)**: Submit bugs found or log feature requests for the `agenda-ts` project.
|
|
301
|
+
- **[Submit Pull Requests](https://github.com/meabed/agenda-ts/pulls)**: Review open PRs, and submit your own PRs.
|
|
302
|
+
- **[Join the Discussions](https://github.com/meabed/agenda-ts/discussions)**: Share your insights, provide feedback, or ask questions.
|
|
303
|
+
|
|
304
|
+
<details closed>
|
|
305
|
+
<summary>Contributing Guidelines</summary>
|
|
306
|
+
|
|
307
|
+
1. **Fork the Repository**: Start by forking the project repository to your github account.
|
|
308
|
+
2. **Clone Locally**: Clone the forked repository to your local machine using a git client.
|
|
309
|
+
```sh
|
|
310
|
+
git clone https://github.com/meabed/agenda-ts
|
|
311
|
+
```
|
|
312
|
+
3. **Create a New Branch**: Always work on a new branch, giving it a descriptive name.
|
|
313
|
+
```sh
|
|
314
|
+
git checkout -b new-feature-x
|
|
315
|
+
```
|
|
316
|
+
4. **Make Your Changes**: Develop and test your changes locally.
|
|
317
|
+
5. **Commit Your Changes**: Commit with a clear message describing your updates.
|
|
318
|
+
```sh
|
|
319
|
+
git commit -m 'Implemented new feature x.'
|
|
320
|
+
```
|
|
321
|
+
6. **Push to github**: Push the changes to your forked repository.
|
|
322
|
+
```sh
|
|
323
|
+
git push origin new-feature-x
|
|
324
|
+
```
|
|
325
|
+
7. **Submit a Pull Request**: Create a PR against the original project repository. Clearly describe the changes and their motivations.
|
|
326
|
+
8. **Review**: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
|
|
327
|
+
</details>
|
|
328
|
+
|
|
329
|
+
<details closed>
|
|
330
|
+
<summary>Contributor Graph</summary>
|
|
331
|
+
<br>
|
|
332
|
+
<p align="center">
|
|
333
|
+
<a href="https://github.com/meabed/agenda-ts/graphs/contributors">
|
|
334
|
+
<img src="https://contrib.rocks/image?repo=meabed/agenda-ts">
|
|
335
|
+
</a>
|
|
336
|
+
</p>
|
|
337
|
+
</details>
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
<br/>
|
|
341
|
+
<br/>
|
|
342
|
+
|
|
343
|
+
## License
|
|
344
|
+
|
|
345
|
+
This project is protected under the [MIT](https://github.com/meabed/agenda-ts?tab=MIT-1-ov-file#readme) License. For more details, refer to the [LICENSE](https://github.com/meabed/agenda-ts?tab=MIT-1-ov-file#readme) file.
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
<br/>
|
|
349
|
+
<br/>
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
## Acknowledgments
|
|
353
|
+
- Agenda-TS is maintained by [Mohamed Meabed](https://github.com/meabed) and was forked from the [Agenda](https://github.com/agenda/agenda) project.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Pulse = exports.JobPriority = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./job"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./pulse"), exports);
|
|
7
|
+
var define_1 = require("./pulse/define");
|
|
8
|
+
Object.defineProperty(exports, "JobPriority", { enumerable: true, get: function () { return define_1.JobPriority; } });
|
|
9
|
+
const pulse_1 = require("./pulse");
|
|
10
|
+
Object.defineProperty(exports, "Pulse", { enumerable: true, get: function () { return pulse_1.Pulse; } });
|
|
11
|
+
exports.default = pulse_1.Pulse;
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AACA,gDAAsB;AACtB,kDAAwB;AAGxB,yCAAuE;AAA/C,qGAAA,WAAW,OAAA;AAGnC,mCAAgC;AAFvB,sFAEA,aAAK,OAFA;AAId,kBAAe,aAAK,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeNextRunAt = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
|
+
const human_interval_1 = tslib_1.__importDefault(require("human-interval"));
|
|
7
|
+
const moment_timezone_1 = tslib_1.__importDefault(require("moment-timezone"));
|
|
8
|
+
const cron_parser_1 = require("cron-parser");
|
|
9
|
+
const date_js_1 = tslib_1.__importDefault(require("date.js"));
|
|
10
|
+
const debug = (0, debug_1.default)('pulse:job');
|
|
11
|
+
const computeNextRunAt = function () {
|
|
12
|
+
const interval = this.attrs.repeatInterval;
|
|
13
|
+
const timezone = this.attrs.repeatTimezone;
|
|
14
|
+
const { repeatAt } = this.attrs;
|
|
15
|
+
const previousNextRunAt = this.attrs.nextRunAt || new Date();
|
|
16
|
+
this.attrs.nextRunAt = undefined;
|
|
17
|
+
const dateForTimezone = (date) => {
|
|
18
|
+
const mdate = (0, moment_timezone_1.default)(date);
|
|
19
|
+
if (timezone) {
|
|
20
|
+
mdate.tz(timezone);
|
|
21
|
+
}
|
|
22
|
+
return mdate;
|
|
23
|
+
};
|
|
24
|
+
const computeFromInterval = () => {
|
|
25
|
+
debug('[%s:%s] computing next run via interval [%s]', this.attrs.name, this.attrs._id, interval);
|
|
26
|
+
const dateNow = new Date();
|
|
27
|
+
let lastRun = this.attrs.lastRunAt || dateNow;
|
|
28
|
+
let { startDate, endDate, skipDays } = this.attrs;
|
|
29
|
+
lastRun = dateForTimezone(lastRun).toDate();
|
|
30
|
+
const cronOptions = { currentDate: lastRun };
|
|
31
|
+
if (timezone) {
|
|
32
|
+
cronOptions.tz = timezone;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
let cronTime = cron_parser_1.CronExpressionParser.parse(interval, cronOptions);
|
|
36
|
+
let nextDate = cronTime.next().toDate();
|
|
37
|
+
if (nextDate.getTime() === lastRun.getTime() || nextDate.getTime() <= previousNextRunAt.getTime()) {
|
|
38
|
+
cronOptions.currentDate = new Date(lastRun.getTime() + 1000);
|
|
39
|
+
cronTime = cron_parser_1.CronExpressionParser.parse(interval, cronOptions);
|
|
40
|
+
nextDate = cronTime.next().toDate();
|
|
41
|
+
}
|
|
42
|
+
if (startDate) {
|
|
43
|
+
startDate = moment_timezone_1.default.tz((0, moment_timezone_1.default)(startDate).format('YYYY-MM-DD HH:mm'), timezone).toDate();
|
|
44
|
+
if (startDate > nextDate) {
|
|
45
|
+
cronOptions.currentDate = startDate;
|
|
46
|
+
cronTime = cron_parser_1.CronExpressionParser.parse(interval, cronOptions);
|
|
47
|
+
nextDate = cronTime.next().toDate();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (dateNow > lastRun && skipDays !== null) {
|
|
51
|
+
try {
|
|
52
|
+
nextDate = new Date(nextDate.getTime() + ((0, human_interval_1.default)(skipDays) ?? 0));
|
|
53
|
+
}
|
|
54
|
+
catch { }
|
|
55
|
+
}
|
|
56
|
+
if (endDate) {
|
|
57
|
+
const endDateDate = moment_timezone_1.default.tz((0, moment_timezone_1.default)(endDate).format('YYYY-MM-DD HH:mm'), timezone).toDate();
|
|
58
|
+
if (nextDate > endDateDate) {
|
|
59
|
+
nextDate = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
this.attrs.nextRunAt = nextDate;
|
|
63
|
+
debug('[%s:%s] nextRunAt set to [%s]', this.attrs.name, this.attrs._id, this.attrs.nextRunAt?.toISOString());
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
debug('[%s:%s] failed nextRunAt based on interval [%s]', this.attrs.name, this.attrs._id, interval);
|
|
67
|
+
try {
|
|
68
|
+
if (!this.attrs.lastRunAt && (0, human_interval_1.default)(interval)) {
|
|
69
|
+
this.attrs.nextRunAt = lastRun;
|
|
70
|
+
debug('[%s:%s] nextRunAt set to [%s]', this.attrs.name, this.attrs._id, this.attrs.nextRunAt.toISOString());
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.attrs.nextRunAt = new Date(lastRun.getTime() + ((0, human_interval_1.default)(interval) ?? 0));
|
|
74
|
+
debug('[%s:%s] nextRunAt set to [%s]', this.attrs.name, this.attrs._id, this.attrs.nextRunAt.toISOString());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch { }
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
if (!this.attrs.nextRunAt?.getTime()) {
|
|
81
|
+
this.attrs.nextRunAt = undefined;
|
|
82
|
+
debug('[%s:%s] failed to calculate nextRunAt due to invalid repeat interval', this.attrs.name, this.attrs._id);
|
|
83
|
+
this.fail('failed to calculate nextRunAt due to invalid repeat interval');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const computeFromRepeatAt = () => {
|
|
88
|
+
const lastRun = this.attrs.lastRunAt || new Date();
|
|
89
|
+
const nextDate = (0, date_js_1.default)(repeatAt);
|
|
90
|
+
const offset = Date.now();
|
|
91
|
+
if (offset === (0, date_js_1.default)(repeatAt, offset).getTime()) {
|
|
92
|
+
this.attrs.nextRunAt = undefined;
|
|
93
|
+
debug('[%s:%s] failed to calculate repeatAt due to invalid format', this.attrs.name, this.attrs._id);
|
|
94
|
+
this.fail('failed to calculate repeatAt time due to invalid format');
|
|
95
|
+
}
|
|
96
|
+
else if (nextDate.getTime() === lastRun.getTime()) {
|
|
97
|
+
this.attrs.nextRunAt = (0, date_js_1.default)('tomorrow at ', repeatAt);
|
|
98
|
+
debug('[%s:%s] nextRunAt set to [%s]', this.attrs.name, this.attrs._id, this.attrs.nextRunAt?.toISOString());
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.attrs.nextRunAt = (0, date_js_1.default)(repeatAt);
|
|
102
|
+
debug('[%s:%s] nextRunAt set to [%s]', this.attrs.name, this.attrs._id, this.attrs.nextRunAt?.toISOString());
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
if (interval) {
|
|
106
|
+
computeFromInterval();
|
|
107
|
+
}
|
|
108
|
+
else if (repeatAt) {
|
|
109
|
+
computeFromRepeatAt();
|
|
110
|
+
}
|
|
111
|
+
return this;
|
|
112
|
+
};
|
|
113
|
+
exports.computeNextRunAt = computeNextRunAt;
|
|
114
|
+
//# sourceMappingURL=compute-next-run-at.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute-next-run-at.js","sourceRoot":"","sources":["../../src/job/compute-next-run-at.ts"],"names":[],"mappings":";;;;AAAA,0DAAmC;AACnC,4EAA2C;AAC3C,8EAAqC;AACrC,6CAAmD;AAGnD,8DAA2B;AAG3B,MAAM,KAAK,GAAG,IAAA,eAAc,EAAC,WAAW,CAAC,CAAC;AAQnC,MAAM,gBAAgB,GAA2B;IACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CA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YACtD,KAAK,CAAC,+BAA+B,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;QAC/G,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,IAAA,iBAAI,EAAC,QAAQ,CAAC,CAAC;YACtC,KAAK,CAAC,+BAA+B,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;QAC/G,CAAC;IACH,CAAC,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,mBAAmB,EAAE,CAAC;IACxB,CAAC;SAAM,IAAI,QAAQ,EAAE,CAAC;QACpB,mBAAmB,EAAE,CAAC;IACxB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAvHW,QAAA,gBAAgB,oBAuH3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disable.js","sourceRoot":"","sources":["../../src/job/disable.ts"],"names":[],"mappings":";;;AAQO,MAAM,OAAO,GAAkB;IACpC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC3B,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAHW,QAAA,OAAO,WAGlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enable.js","sourceRoot":"","sources":["../../src/job/enable.ts"],"names":[],"mappings":";;;AAQO,MAAM,MAAM,GAAiB;IAClC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAHW,QAAA,MAAM,UAGjB"}
|
package/dist/job/fail.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fail = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
|
+
const debug = (0, debug_1.default)('pulse:job');
|
|
7
|
+
const fail = function (reason) {
|
|
8
|
+
const failReason = reason instanceof Error ? reason.message : reason;
|
|
9
|
+
const attrs = this.attrs;
|
|
10
|
+
attrs.failReason = failReason;
|
|
11
|
+
attrs.failCount = (attrs.failCount || 0) + 1;
|
|
12
|
+
attrs.runCount = attrs.runCount || 1;
|
|
13
|
+
const now = new Date();
|
|
14
|
+
attrs.failedAt = attrs.lastFinishedAt = now;
|
|
15
|
+
debug('[%s:%s] fail() called [%d] times so far', attrs.name, attrs._id, attrs.failCount);
|
|
16
|
+
const attempts = attrs.attempts || 0;
|
|
17
|
+
const step = attrs.runCount <= attempts * (attempts + 1) ? Math.ceil(attrs.runCount / (attempts + 1)) : attempts;
|
|
18
|
+
const retryCount = attrs.failCount - step;
|
|
19
|
+
const backoff = attrs.backoff;
|
|
20
|
+
if (attempts && backoff && retryCount < step * attempts) {
|
|
21
|
+
const delayMultiplier = backoff.type === 'fixed' ? 1 : Math.pow(2, retryCount);
|
|
22
|
+
attrs.nextRunAt = new Date(now.getTime() + delayMultiplier * backoff.delay);
|
|
23
|
+
debug('[%s:%s] setting retry at time [%s], retryCount: [%d]', attrs.name, attrs._id, attrs.nextRunAt, retryCount);
|
|
24
|
+
}
|
|
25
|
+
return this;
|
|
26
|
+
};
|
|
27
|
+
exports.fail = fail;
|
|
28
|
+
//# sourceMappingURL=fail.js.map
|