@stonyx/cron 0.0.6 → 0.2.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/.claude/settings.local.json +15 -0
- package/.git/config +24 -0
- package/.github/workflows/ci.yml +36 -0
- package/.npmignore +5 -0
- package/README.md +46 -4
- package/logs/error.log +1 -0
- package/package.json +11 -10
- package/pnpm-lock.yaml +369 -0
- package/src/main.js +17 -1
- package/stonyx-bootstrap.cjs +9 -0
- package/.nvmrc +0 -1
- package/test/min-heap-test.js +0 -79
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(node --version:*)",
|
|
5
|
+
"Bash(source ~/.nvm/nvm.sh)",
|
|
6
|
+
"Bash(nvm use)",
|
|
7
|
+
"Bash(pnpm install:*)",
|
|
8
|
+
"Bash(pnpm store:*)",
|
|
9
|
+
"Bash(npm view:*)",
|
|
10
|
+
"Bash(npm publish:*)",
|
|
11
|
+
"Bash(npm version:*)",
|
|
12
|
+
"Bash(curl:*)"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
}
|
package/.git/config
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[core]
|
|
2
|
+
repositoryformatversion = 0
|
|
3
|
+
filemode = true
|
|
4
|
+
bare = false
|
|
5
|
+
logallrefupdates = true
|
|
6
|
+
ignorecase = true
|
|
7
|
+
precomposeunicode = true
|
|
8
|
+
[remote "origin"]
|
|
9
|
+
url = git@github.com:abofs/stonyx-cron.git
|
|
10
|
+
fetch = +refs/heads/*:refs/remotes/origin/*
|
|
11
|
+
[branch "dev"]
|
|
12
|
+
remote = origin
|
|
13
|
+
merge = refs/heads/dev
|
|
14
|
+
vscode-merge-base = origin/dev
|
|
15
|
+
[branch "stone/cron-updates"]
|
|
16
|
+
remote = origin
|
|
17
|
+
merge = refs/heads/stone/cron-updates
|
|
18
|
+
vscode-merge-base = origin/stone/cron-updates
|
|
19
|
+
gk-last-accessed = 2026-01-26T20:25:14.543Z
|
|
20
|
+
gk-last-modified = 2026-01-26T20:25:14.543Z
|
|
21
|
+
[branch "main"]
|
|
22
|
+
remote = origin
|
|
23
|
+
merge = refs/heads/main
|
|
24
|
+
vscode-merge-base = origin/main
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- dev
|
|
7
|
+
- main
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ci-${{ github.head_ref || github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout code
|
|
19
|
+
uses: actions/checkout@v3
|
|
20
|
+
|
|
21
|
+
- name: Setup pnpm
|
|
22
|
+
uses: pnpm/action-setup@v4
|
|
23
|
+
with:
|
|
24
|
+
version: 9
|
|
25
|
+
|
|
26
|
+
- name: Set up Node.js
|
|
27
|
+
uses: actions/setup-node@v3
|
|
28
|
+
with:
|
|
29
|
+
node-version: 22.18.0
|
|
30
|
+
cache: 'pnpm'
|
|
31
|
+
|
|
32
|
+
- name: Install dependencies
|
|
33
|
+
run: pnpm install --frozen-lockfile
|
|
34
|
+
|
|
35
|
+
- name: Run tests
|
|
36
|
+
run: pnpm test
|
package/README.md
CHANGED
|
@@ -1,9 +1,51 @@
|
|
|
1
1
|
# stonyx-cron
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A small, lightweight cron/job scheduling utility for asynchronous jobs. Designed to schedule, run, and automatically re-schedule jobs at precise intervals with optional debug logging.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import Cron from '@stonyx/cron';
|
|
9
|
+
|
|
10
|
+
const cron = new Cron();
|
|
11
|
+
|
|
12
|
+
// Register a job to run every 5 seconds
|
|
13
|
+
cron.register('exampleJob', async () => {
|
|
14
|
+
console.log('Job executed!');
|
|
15
|
+
}, 5, true);
|
|
16
|
+
|
|
17
|
+
// Unregister the job when no longer needed
|
|
18
|
+
// cron.unregister('exampleJob');
|
|
4
19
|
```
|
|
5
|
-
|
|
20
|
+
|
|
21
|
+
## How it works
|
|
22
|
+
|
|
23
|
+
`stonyx-cron` uses a min-heap internally to efficiently track the next job to run. Each job has a scheduled trigger time, and the heap ensures the job with the earliest trigger is always at the top.
|
|
24
|
+
|
|
25
|
+
When a job is executed, its next trigger time is updated, and it is re-inserted into the heap. This allows `Cron` to always know which job should run next without scanning all jobs, keeping scheduling efficient even with many jobs.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Public Methods
|
|
29
|
+
|
|
30
|
+
| Method | Parameters | Description |
|
|
31
|
+
| :----------: | :----------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------- |
|
|
32
|
+
| `register` | `key: string, callback: Function, interval: number, runOnInit?: boolean` | Register a new job with a given interval in seconds. If `runOnInit` is true, the job runs immediately upon registration. |
|
|
33
|
+
| `unregister` | `key: string` | Remove a previously registered job. |
|
|
34
|
+
|
|
35
|
+
> All other methods and classes (like `MinHeap`) are used internally by `Cron` and are not intended for direct use.
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
Optionally, logging and debugging can be enabled through `config.cron`:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
config.cron = {
|
|
43
|
+
log: true // enable cron job logs
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
config.debug = true; // optional: debug logs for job registration and execution
|
|
6
47
|
```
|
|
7
48
|
|
|
8
|
-
##
|
|
9
|
-
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
Apache — do what you want, just keep attribution.
|
package/logs/error.log
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[12/31/1969, 7:00:01 PM] Cron job "jobErr" failed:
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonyx/cron",
|
|
3
3
|
"keywords": [
|
|
4
|
-
"stonyx-async",
|
|
5
4
|
"stonyx-module"
|
|
6
5
|
],
|
|
7
|
-
"version": "0.0
|
|
6
|
+
"version": "0.2.0",
|
|
8
7
|
"description": "",
|
|
9
8
|
"main": "src/main.js",
|
|
10
9
|
"type": "module",
|
|
@@ -12,10 +11,8 @@
|
|
|
12
11
|
"*"
|
|
13
12
|
],
|
|
14
13
|
"exports": {
|
|
15
|
-
".": "./src/main.js"
|
|
16
|
-
|
|
17
|
-
"scripts": {
|
|
18
|
-
"test": "qunit"
|
|
14
|
+
".": "./src/main.js",
|
|
15
|
+
"./min-heap": "./src/min-heap.js"
|
|
19
16
|
},
|
|
20
17
|
"repository": {
|
|
21
18
|
"type": "git",
|
|
@@ -31,10 +28,14 @@
|
|
|
31
28
|
},
|
|
32
29
|
"homepage": "https://github.com/abofs/stonyx-cron#readme",
|
|
33
30
|
"devDependencies": {
|
|
34
|
-
"@stonyx/utils": "^0.
|
|
35
|
-
"qunit": "^2.24.1"
|
|
31
|
+
"@stonyx/utils": "^0.2.2",
|
|
32
|
+
"qunit": "^2.24.1",
|
|
33
|
+
"sinon": "^21.0.0"
|
|
36
34
|
},
|
|
37
35
|
"dependencies": {
|
|
38
|
-
"stonyx": "^0.
|
|
36
|
+
"stonyx": "^0.2.2"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"test": "qunit --require ./stonyx-bootstrap.cjs"
|
|
39
40
|
}
|
|
40
|
-
}
|
|
41
|
+
}
|
package/pnpm-lock.yaml
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
lockfileVersion: '9.0'
|
|
2
|
+
|
|
3
|
+
settings:
|
|
4
|
+
autoInstallPeers: true
|
|
5
|
+
excludeLinksFromLockfile: false
|
|
6
|
+
|
|
7
|
+
importers:
|
|
8
|
+
|
|
9
|
+
.:
|
|
10
|
+
dependencies:
|
|
11
|
+
stonyx:
|
|
12
|
+
specifier: ^0.2.2
|
|
13
|
+
version: 0.2.2
|
|
14
|
+
devDependencies:
|
|
15
|
+
'@stonyx/utils':
|
|
16
|
+
specifier: ^0.2.2
|
|
17
|
+
version: 0.2.2
|
|
18
|
+
qunit:
|
|
19
|
+
specifier: ^2.24.1
|
|
20
|
+
version: 2.25.0
|
|
21
|
+
sinon:
|
|
22
|
+
specifier: ^21.0.0
|
|
23
|
+
version: 21.0.1
|
|
24
|
+
|
|
25
|
+
packages:
|
|
26
|
+
|
|
27
|
+
'@sinonjs/commons@3.0.1':
|
|
28
|
+
resolution: {integrity: sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==}
|
|
29
|
+
|
|
30
|
+
'@sinonjs/fake-timers@15.1.0':
|
|
31
|
+
resolution: {integrity: sha512-cqfapCxwTGsrR80FEgOoPsTonoefMBY7dnUEbQ+GRcved0jvkJLzvX6F4WtN+HBqbPX/SiFsIRUp+IrCW/2I2w==}
|
|
32
|
+
|
|
33
|
+
'@sinonjs/samsam@8.0.3':
|
|
34
|
+
resolution: {integrity: sha512-hw6HbX+GyVZzmaYNh82Ecj1vdGZrqVIn/keDTg63IgAwiQPO+xCz99uG6Woqgb4tM0mUiFENKZ4cqd7IX94AXQ==}
|
|
35
|
+
|
|
36
|
+
'@stonyx/utils@0.2.2':
|
|
37
|
+
resolution: {integrity: sha512-z/pDbX3QPeVJ3kFpU1rQURj3+BLwvGkLHVJiSckmjaBZ/vQIZzaerkf6BTZnHbSmQuUwO0lFzJRwlKOTIaXp0g==}
|
|
38
|
+
|
|
39
|
+
call-bind-apply-helpers@1.0.2:
|
|
40
|
+
resolution: {integrity: sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==}
|
|
41
|
+
engines: {node: '>= 0.4'}
|
|
42
|
+
|
|
43
|
+
call-bound@1.0.4:
|
|
44
|
+
resolution: {integrity: sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==}
|
|
45
|
+
engines: {node: '>= 0.4'}
|
|
46
|
+
|
|
47
|
+
chalk@5.6.2:
|
|
48
|
+
resolution: {integrity: sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==}
|
|
49
|
+
engines: {node: ^12.17.0 || ^14.13 || >=16.0.0}
|
|
50
|
+
|
|
51
|
+
commander@7.2.0:
|
|
52
|
+
resolution: {integrity: sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==}
|
|
53
|
+
engines: {node: '>= 10'}
|
|
54
|
+
|
|
55
|
+
diff@8.0.3:
|
|
56
|
+
resolution: {integrity: sha512-qejHi7bcSD4hQAZE0tNAawRK1ZtafHDmMTMkrrIGgSLl7hTnQHmKCeB45xAcbfTqK2zowkM3j3bHt/4b/ARbYQ==}
|
|
57
|
+
engines: {node: '>=0.3.1'}
|
|
58
|
+
|
|
59
|
+
dunder-proto@1.0.1:
|
|
60
|
+
resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==}
|
|
61
|
+
engines: {node: '>= 0.4'}
|
|
62
|
+
|
|
63
|
+
es-define-property@1.0.1:
|
|
64
|
+
resolution: {integrity: sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==}
|
|
65
|
+
engines: {node: '>= 0.4'}
|
|
66
|
+
|
|
67
|
+
es-errors@1.3.0:
|
|
68
|
+
resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==}
|
|
69
|
+
engines: {node: '>= 0.4'}
|
|
70
|
+
|
|
71
|
+
es-object-atoms@1.1.1:
|
|
72
|
+
resolution: {integrity: sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==}
|
|
73
|
+
engines: {node: '>= 0.4'}
|
|
74
|
+
|
|
75
|
+
fs@0.0.1-security:
|
|
76
|
+
resolution: {integrity: sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==}
|
|
77
|
+
|
|
78
|
+
function-bind@1.1.2:
|
|
79
|
+
resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==}
|
|
80
|
+
|
|
81
|
+
get-intrinsic@1.3.0:
|
|
82
|
+
resolution: {integrity: sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==}
|
|
83
|
+
engines: {node: '>= 0.4'}
|
|
84
|
+
|
|
85
|
+
get-proto@1.0.1:
|
|
86
|
+
resolution: {integrity: sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==}
|
|
87
|
+
engines: {node: '>= 0.4'}
|
|
88
|
+
|
|
89
|
+
globalyzer@0.1.0:
|
|
90
|
+
resolution: {integrity: sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==}
|
|
91
|
+
|
|
92
|
+
globrex@0.1.2:
|
|
93
|
+
resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==}
|
|
94
|
+
|
|
95
|
+
gopd@1.2.0:
|
|
96
|
+
resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==}
|
|
97
|
+
engines: {node: '>= 0.4'}
|
|
98
|
+
|
|
99
|
+
has-flag@4.0.0:
|
|
100
|
+
resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==}
|
|
101
|
+
engines: {node: '>=8'}
|
|
102
|
+
|
|
103
|
+
has-symbols@1.1.0:
|
|
104
|
+
resolution: {integrity: sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==}
|
|
105
|
+
engines: {node: '>= 0.4'}
|
|
106
|
+
|
|
107
|
+
hasown@2.0.2:
|
|
108
|
+
resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==}
|
|
109
|
+
engines: {node: '>= 0.4'}
|
|
110
|
+
|
|
111
|
+
inherits@2.0.3:
|
|
112
|
+
resolution: {integrity: sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==}
|
|
113
|
+
|
|
114
|
+
math-intrinsics@1.1.0:
|
|
115
|
+
resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==}
|
|
116
|
+
engines: {node: '>= 0.4'}
|
|
117
|
+
|
|
118
|
+
node-chronicle@0.2.0:
|
|
119
|
+
resolution: {integrity: sha512-se9NsW67UZqDFbK/+Rbml9KdCVTwzaadIgL4NDBcDpLMhOf1qerRxXicE+/dBsoyhDqWCwAFbBjR3iytF3gepA==}
|
|
120
|
+
|
|
121
|
+
node-watch@0.7.3:
|
|
122
|
+
resolution: {integrity: sha512-3l4E8uMPY1HdMMryPRUAl+oIHtXtyiTlIiESNSVSNxcPfzAFzeTbXFQkZfAwBbo0B1qMSG8nUABx+Gd+YrbKrQ==}
|
|
123
|
+
engines: {node: '>=6'}
|
|
124
|
+
|
|
125
|
+
object-inspect@1.13.4:
|
|
126
|
+
resolution: {integrity: sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==}
|
|
127
|
+
engines: {node: '>= 0.4'}
|
|
128
|
+
|
|
129
|
+
path@0.12.7:
|
|
130
|
+
resolution: {integrity: sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==}
|
|
131
|
+
|
|
132
|
+
process@0.11.10:
|
|
133
|
+
resolution: {integrity: sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==}
|
|
134
|
+
engines: {node: '>= 0.6.0'}
|
|
135
|
+
|
|
136
|
+
punycode@1.4.1:
|
|
137
|
+
resolution: {integrity: sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==}
|
|
138
|
+
|
|
139
|
+
qs@6.14.1:
|
|
140
|
+
resolution: {integrity: sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==}
|
|
141
|
+
engines: {node: '>=0.6'}
|
|
142
|
+
|
|
143
|
+
qunit@2.25.0:
|
|
144
|
+
resolution: {integrity: sha512-MONPKgjavgTqArCwZOEz8nEMbA19zNXIp5ZOW9rPYj5cbgQp0fiI36c9dPTSzTRRzx+KcfB5eggYB/ENqxi0+w==}
|
|
145
|
+
engines: {node: '>=10'}
|
|
146
|
+
hasBin: true
|
|
147
|
+
|
|
148
|
+
side-channel-list@1.0.0:
|
|
149
|
+
resolution: {integrity: sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==}
|
|
150
|
+
engines: {node: '>= 0.4'}
|
|
151
|
+
|
|
152
|
+
side-channel-map@1.0.1:
|
|
153
|
+
resolution: {integrity: sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==}
|
|
154
|
+
engines: {node: '>= 0.4'}
|
|
155
|
+
|
|
156
|
+
side-channel-weakmap@1.0.2:
|
|
157
|
+
resolution: {integrity: sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==}
|
|
158
|
+
engines: {node: '>= 0.4'}
|
|
159
|
+
|
|
160
|
+
side-channel@1.1.0:
|
|
161
|
+
resolution: {integrity: sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==}
|
|
162
|
+
engines: {node: '>= 0.4'}
|
|
163
|
+
|
|
164
|
+
sinon@21.0.1:
|
|
165
|
+
resolution: {integrity: sha512-Z0NVCW45W8Mg5oC/27/+fCqIHFnW8kpkFOq0j9XJIev4Ld0mKmERaZv5DMLAb9fGCevjKwaEeIQz5+MBXfZcDw==}
|
|
166
|
+
|
|
167
|
+
stonyx@0.2.2:
|
|
168
|
+
resolution: {integrity: sha512-X37/2R2YklI+CX4wKHckPg2pFmOL1hk0CwOMvn7E00sE+8JjhmbHvAeTI+0t50kufBsXKREPX3FBHVUd4Yi4Fw==}
|
|
169
|
+
|
|
170
|
+
supports-color@7.2.0:
|
|
171
|
+
resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==}
|
|
172
|
+
engines: {node: '>=8'}
|
|
173
|
+
|
|
174
|
+
tiny-glob@0.2.9:
|
|
175
|
+
resolution: {integrity: sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==}
|
|
176
|
+
|
|
177
|
+
type-detect@4.0.8:
|
|
178
|
+
resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==}
|
|
179
|
+
engines: {node: '>=4'}
|
|
180
|
+
|
|
181
|
+
type-detect@4.1.0:
|
|
182
|
+
resolution: {integrity: sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==}
|
|
183
|
+
engines: {node: '>=4'}
|
|
184
|
+
|
|
185
|
+
url@0.11.4:
|
|
186
|
+
resolution: {integrity: sha512-oCwdVC7mTuWiPyjLUz/COz5TLk6wgp0RCsN+wHZ2Ekneac9w8uuV0njcbbie2ME+Vs+d6duwmYuR3HgQXs1fOg==}
|
|
187
|
+
engines: {node: '>= 0.4'}
|
|
188
|
+
|
|
189
|
+
util@0.10.4:
|
|
190
|
+
resolution: {integrity: sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==}
|
|
191
|
+
|
|
192
|
+
snapshots:
|
|
193
|
+
|
|
194
|
+
'@sinonjs/commons@3.0.1':
|
|
195
|
+
dependencies:
|
|
196
|
+
type-detect: 4.0.8
|
|
197
|
+
|
|
198
|
+
'@sinonjs/fake-timers@15.1.0':
|
|
199
|
+
dependencies:
|
|
200
|
+
'@sinonjs/commons': 3.0.1
|
|
201
|
+
|
|
202
|
+
'@sinonjs/samsam@8.0.3':
|
|
203
|
+
dependencies:
|
|
204
|
+
'@sinonjs/commons': 3.0.1
|
|
205
|
+
type-detect: 4.1.0
|
|
206
|
+
|
|
207
|
+
'@stonyx/utils@0.2.2': {}
|
|
208
|
+
|
|
209
|
+
call-bind-apply-helpers@1.0.2:
|
|
210
|
+
dependencies:
|
|
211
|
+
es-errors: 1.3.0
|
|
212
|
+
function-bind: 1.1.2
|
|
213
|
+
|
|
214
|
+
call-bound@1.0.4:
|
|
215
|
+
dependencies:
|
|
216
|
+
call-bind-apply-helpers: 1.0.2
|
|
217
|
+
get-intrinsic: 1.3.0
|
|
218
|
+
|
|
219
|
+
chalk@5.6.2: {}
|
|
220
|
+
|
|
221
|
+
commander@7.2.0: {}
|
|
222
|
+
|
|
223
|
+
diff@8.0.3: {}
|
|
224
|
+
|
|
225
|
+
dunder-proto@1.0.1:
|
|
226
|
+
dependencies:
|
|
227
|
+
call-bind-apply-helpers: 1.0.2
|
|
228
|
+
es-errors: 1.3.0
|
|
229
|
+
gopd: 1.2.0
|
|
230
|
+
|
|
231
|
+
es-define-property@1.0.1: {}
|
|
232
|
+
|
|
233
|
+
es-errors@1.3.0: {}
|
|
234
|
+
|
|
235
|
+
es-object-atoms@1.1.1:
|
|
236
|
+
dependencies:
|
|
237
|
+
es-errors: 1.3.0
|
|
238
|
+
|
|
239
|
+
fs@0.0.1-security: {}
|
|
240
|
+
|
|
241
|
+
function-bind@1.1.2: {}
|
|
242
|
+
|
|
243
|
+
get-intrinsic@1.3.0:
|
|
244
|
+
dependencies:
|
|
245
|
+
call-bind-apply-helpers: 1.0.2
|
|
246
|
+
es-define-property: 1.0.1
|
|
247
|
+
es-errors: 1.3.0
|
|
248
|
+
es-object-atoms: 1.1.1
|
|
249
|
+
function-bind: 1.1.2
|
|
250
|
+
get-proto: 1.0.1
|
|
251
|
+
gopd: 1.2.0
|
|
252
|
+
has-symbols: 1.1.0
|
|
253
|
+
hasown: 2.0.2
|
|
254
|
+
math-intrinsics: 1.1.0
|
|
255
|
+
|
|
256
|
+
get-proto@1.0.1:
|
|
257
|
+
dependencies:
|
|
258
|
+
dunder-proto: 1.0.1
|
|
259
|
+
es-object-atoms: 1.1.1
|
|
260
|
+
|
|
261
|
+
globalyzer@0.1.0: {}
|
|
262
|
+
|
|
263
|
+
globrex@0.1.2: {}
|
|
264
|
+
|
|
265
|
+
gopd@1.2.0: {}
|
|
266
|
+
|
|
267
|
+
has-flag@4.0.0: {}
|
|
268
|
+
|
|
269
|
+
has-symbols@1.1.0: {}
|
|
270
|
+
|
|
271
|
+
hasown@2.0.2:
|
|
272
|
+
dependencies:
|
|
273
|
+
function-bind: 1.1.2
|
|
274
|
+
|
|
275
|
+
inherits@2.0.3: {}
|
|
276
|
+
|
|
277
|
+
math-intrinsics@1.1.0: {}
|
|
278
|
+
|
|
279
|
+
node-chronicle@0.2.0:
|
|
280
|
+
dependencies:
|
|
281
|
+
chalk: 5.6.2
|
|
282
|
+
fs: 0.0.1-security
|
|
283
|
+
path: 0.12.7
|
|
284
|
+
url: 0.11.4
|
|
285
|
+
|
|
286
|
+
node-watch@0.7.3: {}
|
|
287
|
+
|
|
288
|
+
object-inspect@1.13.4: {}
|
|
289
|
+
|
|
290
|
+
path@0.12.7:
|
|
291
|
+
dependencies:
|
|
292
|
+
process: 0.11.10
|
|
293
|
+
util: 0.10.4
|
|
294
|
+
|
|
295
|
+
process@0.11.10: {}
|
|
296
|
+
|
|
297
|
+
punycode@1.4.1: {}
|
|
298
|
+
|
|
299
|
+
qs@6.14.1:
|
|
300
|
+
dependencies:
|
|
301
|
+
side-channel: 1.1.0
|
|
302
|
+
|
|
303
|
+
qunit@2.25.0:
|
|
304
|
+
dependencies:
|
|
305
|
+
commander: 7.2.0
|
|
306
|
+
node-watch: 0.7.3
|
|
307
|
+
tiny-glob: 0.2.9
|
|
308
|
+
|
|
309
|
+
side-channel-list@1.0.0:
|
|
310
|
+
dependencies:
|
|
311
|
+
es-errors: 1.3.0
|
|
312
|
+
object-inspect: 1.13.4
|
|
313
|
+
|
|
314
|
+
side-channel-map@1.0.1:
|
|
315
|
+
dependencies:
|
|
316
|
+
call-bound: 1.0.4
|
|
317
|
+
es-errors: 1.3.0
|
|
318
|
+
get-intrinsic: 1.3.0
|
|
319
|
+
object-inspect: 1.13.4
|
|
320
|
+
|
|
321
|
+
side-channel-weakmap@1.0.2:
|
|
322
|
+
dependencies:
|
|
323
|
+
call-bound: 1.0.4
|
|
324
|
+
es-errors: 1.3.0
|
|
325
|
+
get-intrinsic: 1.3.0
|
|
326
|
+
object-inspect: 1.13.4
|
|
327
|
+
side-channel-map: 1.0.1
|
|
328
|
+
|
|
329
|
+
side-channel@1.1.0:
|
|
330
|
+
dependencies:
|
|
331
|
+
es-errors: 1.3.0
|
|
332
|
+
object-inspect: 1.13.4
|
|
333
|
+
side-channel-list: 1.0.0
|
|
334
|
+
side-channel-map: 1.0.1
|
|
335
|
+
side-channel-weakmap: 1.0.2
|
|
336
|
+
|
|
337
|
+
sinon@21.0.1:
|
|
338
|
+
dependencies:
|
|
339
|
+
'@sinonjs/commons': 3.0.1
|
|
340
|
+
'@sinonjs/fake-timers': 15.1.0
|
|
341
|
+
'@sinonjs/samsam': 8.0.3
|
|
342
|
+
diff: 8.0.3
|
|
343
|
+
supports-color: 7.2.0
|
|
344
|
+
|
|
345
|
+
stonyx@0.2.2:
|
|
346
|
+
dependencies:
|
|
347
|
+
node-chronicle: 0.2.0
|
|
348
|
+
|
|
349
|
+
supports-color@7.2.0:
|
|
350
|
+
dependencies:
|
|
351
|
+
has-flag: 4.0.0
|
|
352
|
+
|
|
353
|
+
tiny-glob@0.2.9:
|
|
354
|
+
dependencies:
|
|
355
|
+
globalyzer: 0.1.0
|
|
356
|
+
globrex: 0.1.2
|
|
357
|
+
|
|
358
|
+
type-detect@4.0.8: {}
|
|
359
|
+
|
|
360
|
+
type-detect@4.1.0: {}
|
|
361
|
+
|
|
362
|
+
url@0.11.4:
|
|
363
|
+
dependencies:
|
|
364
|
+
punycode: 1.4.1
|
|
365
|
+
qs: 6.14.1
|
|
366
|
+
|
|
367
|
+
util@0.10.4:
|
|
368
|
+
dependencies:
|
|
369
|
+
inherits: 2.0.3
|
package/src/main.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Stone Costa
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
1
17
|
import config from 'stonyx/config';
|
|
2
18
|
import log from 'stonyx/log';
|
|
3
19
|
import { getTimestamp } from "@stonyx/utils/date";
|
|
4
|
-
import MinHeap from '
|
|
20
|
+
import MinHeap from '@stonyx/cron/min-heap';
|
|
5
21
|
|
|
6
22
|
export default class Cron {
|
|
7
23
|
jobs = {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* commonJS Bootstrap loading - Stonyx must be loaded first, prior to the rest of the application
|
|
3
|
+
*/
|
|
4
|
+
const { default:Stonyx } = require('stonyx');
|
|
5
|
+
const { default:config } = require('./config/environment.js');
|
|
6
|
+
|
|
7
|
+
new Stonyx(config, __dirname);
|
|
8
|
+
|
|
9
|
+
module.exports = Stonyx;
|
package/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
v22.18.0
|
package/test/min-heap-test.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import QUnit from 'qunit';
|
|
2
|
-
import MinHeap from '../src/min-heap.js';
|
|
3
|
-
|
|
4
|
-
const { module, test } = QUnit;
|
|
5
|
-
|
|
6
|
-
module('[Unit] MinHeap', function () {
|
|
7
|
-
test('push and peek should return the smallest nextTrigger job', function (assert) {
|
|
8
|
-
const heap = new MinHeap();
|
|
9
|
-
const job1 = { nextTrigger: 5 };
|
|
10
|
-
const job2 = { nextTrigger: 2 };
|
|
11
|
-
const job3 = { nextTrigger: 8 };
|
|
12
|
-
|
|
13
|
-
heap.push(job1);
|
|
14
|
-
heap.push(job2);
|
|
15
|
-
heap.push(job3);
|
|
16
|
-
|
|
17
|
-
assert.strictEqual(heap.peek(), job2, 'Job with smallest nextTrigger is at the top');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('pop should remove and return the smallest job', function (assert) {
|
|
21
|
-
const heap = new MinHeap();
|
|
22
|
-
const job1 = { nextTrigger: 5 };
|
|
23
|
-
const job2 = { nextTrigger: 2 };
|
|
24
|
-
const job3 = { nextTrigger: 8 };
|
|
25
|
-
|
|
26
|
-
heap.push(job1);
|
|
27
|
-
heap.push(job2);
|
|
28
|
-
heap.push(job3);
|
|
29
|
-
|
|
30
|
-
const popped = heap.pop();
|
|
31
|
-
assert.strictEqual(popped, job2, 'Popped job is the smallest');
|
|
32
|
-
assert.strictEqual(heap.peek(), job1, 'Next smallest job is now at the top');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('isEmpty should correctly reflect heap state', function (assert) {
|
|
36
|
-
const heap = new MinHeap();
|
|
37
|
-
assert.ok(heap.isEmpty(), 'Heap is empty initially');
|
|
38
|
-
|
|
39
|
-
heap.push({ nextTrigger: 1 });
|
|
40
|
-
assert.notOk(heap.isEmpty(), 'Heap is not empty after adding a job');
|
|
41
|
-
|
|
42
|
-
heap.pop();
|
|
43
|
-
assert.ok(heap.isEmpty(), 'Heap is empty after removing last job');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('remove should delete a specific job from the heap', function (assert) {
|
|
47
|
-
const heap = new MinHeap();
|
|
48
|
-
const job1 = { nextTrigger: 5 };
|
|
49
|
-
const job2 = { nextTrigger: 2 };
|
|
50
|
-
const job3 = { nextTrigger: 8 };
|
|
51
|
-
|
|
52
|
-
heap.push(job1);
|
|
53
|
-
heap.push(job2);
|
|
54
|
-
heap.push(job3);
|
|
55
|
-
|
|
56
|
-
heap.remove(job2);
|
|
57
|
-
assert.notStrictEqual(heap.peek(), job2, 'Removed job is no longer in heap');
|
|
58
|
-
assert.ok([job1, job3].includes(heap.peek()), 'Heap still has remaining jobs');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('pop should work correctly when only one item is in heap', function (assert) {
|
|
62
|
-
const heap = new MinHeap();
|
|
63
|
-
const job = { nextTrigger: 1 };
|
|
64
|
-
heap.push(job);
|
|
65
|
-
|
|
66
|
-
assert.strictEqual(heap.pop(), job, 'Popped the only job in the heap');
|
|
67
|
-
assert.ok(heap.isEmpty(), 'Heap is empty after popping last job');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('pop should return undefined if heap is empty', function (assert) {
|
|
71
|
-
const heap = new MinHeap();
|
|
72
|
-
assert.strictEqual(heap.pop(), undefined, 'Pop returns undefined for empty heap');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('peek should return undefined if heap is empty', function (assert) {
|
|
76
|
-
const heap = new MinHeap();
|
|
77
|
-
assert.strictEqual(heap.peek(), undefined, 'Peek returns undefined for empty heap');
|
|
78
|
-
});
|
|
79
|
-
});
|