@stonyx/cron 0.2.1-beta.9 → 0.2.1-beta.91

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.
@@ -1,85 +0,0 @@
1
- # Testing Guidelines
2
-
3
- ## Testing Guidelines
4
-
5
- ### Test Structure
6
- Tests are located in `stonyx-cron/test/unit/` and use QUnit modules:
7
-
8
- ```javascript
9
- import QUnit from 'qunit';
10
- import sinon from 'sinon';
11
- import { setupIntegrationTests } from "stonyx/test-helpers";
12
-
13
- const { module, test } = QUnit;
14
-
15
- module('[Unit] Cron', function (hooks) {
16
- setupIntegrationTests(hooks);
17
-
18
- let cron, clock;
19
-
20
- hooks.beforeEach(function () {
21
- clock = sinon.useFakeTimers({ shouldAdvanceTime: false });
22
- cron = new Cron();
23
- });
24
-
25
- hooks.afterEach(function () {
26
- sinon.restore();
27
- });
28
-
29
- test('test description', async function (assert) {
30
- // Test implementation
31
- });
32
- });
33
- ```
34
-
35
- ### Fake Timers Pattern (CRITICAL)
36
- **Always use fake timers for time-based tests:**
37
-
38
- ```javascript
39
- // Setup in beforeEach
40
- clock = sinon.useFakeTimers({ shouldAdvanceTime: false });
41
-
42
- // Advance time synchronously
43
- clock.tick(5000); // Advance 5 seconds
44
-
45
- // For async operations, use tickAsync
46
- clock.tick(5000);
47
- await clock.tickAsync(0); // Process async callbacks
48
-
49
- // Cleanup in afterEach
50
- sinon.restore();
51
- ```
52
-
53
- **Why `shouldAdvanceTime: false`?**
54
- Prevents real time from interfering with fake time, ensuring deterministic tests.
55
-
56
- ### Spies & Stubs Patterns
57
- ```javascript
58
- // Spy on function calls
59
- const cb = sinon.spy();
60
- cron.register('job1', cb, 5);
61
- assert.ok(cb.calledOnce, 'Callback executed once');
62
-
63
- // Stub methods
64
- const stub = sinon.stub().rejects(new Error('boom'));
65
- cron.register('jobErr', stub, 1);
66
-
67
- // Spy on existing methods
68
- const logSpy = sinon.spy(log, 'cron');
69
- cron.log('test message');
70
- assert.ok(logSpy.calledOnce, 'Log called');
71
- ```
72
-
73
- ### Test Coverage Expectations
74
- Tests should cover:
75
- - Job registration and execution
76
- - Rescheduling behavior
77
- - Unregistration
78
- - Error handling
79
- - Configuration-driven logging
80
- - Edge cases (empty heap, multiple jobs, etc.)
81
-
82
- ### Running Tests
83
- ```bash
84
- pnpm test # Runs: stonyx test
85
- ```
package/.git/config DELETED
@@ -1,18 +0,0 @@
1
- [core]
2
- repositoryformatversion = 0
3
- filemode = true
4
- bare = false
5
- logallrefupdates = true
6
- [remote "origin"]
7
- url = https://github.com/abofs/stonyx-cron
8
- fetch = +refs/heads/*:refs/remotes/origin/*
9
- [gc]
10
- auto = 0
11
- [http "https://github.com/"]
12
- extraheader = AUTHORIZATION: basic eC1hY2Nlc3MtdG9rZW46Z2hwX2hBdU5WbnJNcml2bktkZTlmaU80WW9lZk9QenZtdTFiUWtQNA==
13
- [branch "main"]
14
- remote = origin
15
- merge = refs/heads/main
16
- [user]
17
- name = github-actions[bot]
18
- email = github-actions[bot]@users.noreply.github.com
@@ -1,16 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- pull_request:
5
- branches: [dev, main]
6
-
7
- concurrency:
8
- group: ci-${{ github.head_ref || github.ref }}
9
- cancel-in-progress: true
10
-
11
- permissions:
12
- contents: read
13
-
14
- jobs:
15
- test:
16
- uses: abofs/stonyx-workflows/.github/workflows/ci.yml@main
@@ -1,51 +0,0 @@
1
- name: Publish to NPM
2
-
3
- on:
4
- repository_dispatch:
5
- types: [cascade-publish]
6
- workflow_dispatch:
7
- inputs:
8
- version-type:
9
- description: 'Version type'
10
- required: true
11
- type: choice
12
- options:
13
- - patch
14
- - minor
15
- - major
16
- custom-version:
17
- description: 'Custom version (optional, overrides version-type)'
18
- required: false
19
- type: string
20
- pull_request:
21
- types: [opened, synchronize, reopened]
22
- branches: [main]
23
- push:
24
- branches: [main]
25
-
26
- concurrency:
27
- group: ${{ github.event_name == 'repository_dispatch' && 'cascade-update' || format('publish-{0}', github.ref) }}
28
- cancel-in-progress: false
29
-
30
- permissions:
31
- contents: write
32
- id-token: write
33
- pull-requests: write
34
-
35
- jobs:
36
- publish:
37
- if: "!contains(github.event.head_commit.message, '[skip ci]')"
38
- uses: abofs/stonyx-workflows/.github/workflows/npm-publish.yml@main
39
- with:
40
- version-type: ${{ github.event.inputs.version-type }}
41
- custom-version: ${{ github.event.inputs.custom-version }}
42
- cascade-source: ${{ github.event.client_payload.source_package || '' }}
43
- secrets: inherit
44
-
45
- cascade:
46
- needs: publish
47
- uses: abofs/stonyx-workflows/.github/workflows/cascade.yml@main
48
- with:
49
- package-name: ${{ needs.publish.outputs.package-name }}
50
- published-version: ${{ needs.publish.outputs.published-version }}
51
- secrets: inherit
package/.gitignore DELETED
@@ -1,16 +0,0 @@
1
- # dependencies
2
- /node_modules/
3
-
4
- # config
5
- config/environment.js
6
-
7
- # logs
8
- *logs/*
9
-
10
- # os / IDE
11
- .vscode/*
12
- *.vsix%
13
- *DS_Store*
14
-
15
- # npm auth (never commit tokens)
16
- .npmrc
package/.npmignore DELETED
@@ -1,5 +0,0 @@
1
- # tests
2
- test/
3
-
4
- # config
5
- .nvmrc
package/logs/error.log DELETED
@@ -1,2 +0,0 @@
1
- [1/1/1970, 12:00:01 AM] Cron job "jobErr" failed:
2
- [1/1/1970, 12:00:01 AM] Cron job "jobErr" failed:
package/pnpm-lock.yaml DELETED
@@ -1,370 +0,0 @@
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.3-beta.4
13
- version: 0.2.3-beta.4
14
- devDependencies:
15
- '@stonyx/utils':
16
- specifier: 0.2.3-beta.4
17
- version: 0.2.3-beta.4
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.3-beta.4':
37
- resolution: {integrity: sha512-3w2nTh9UqHSnhCKWP92ynupOYLuECkQKB2Xlex8x4UTJb9hgCMtcn+D0XGHX85AjgsW9VaL0p9cTE5LurXi/fA==}
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.3-beta.4:
168
- resolution: {integrity: sha512-fP65yuUbHTzPi6LTT3ee6vMvA/C1EJfJC9ZfS/Q2Uf1J1iEdERq3onlnYq6aJcryum7+uvDsqZyEKzn6k3nWCA==}
169
- hasBin: true
170
-
171
- supports-color@7.2.0:
172
- resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==}
173
- engines: {node: '>=8'}
174
-
175
- tiny-glob@0.2.9:
176
- resolution: {integrity: sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==}
177
-
178
- type-detect@4.0.8:
179
- resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==}
180
- engines: {node: '>=4'}
181
-
182
- type-detect@4.1.0:
183
- resolution: {integrity: sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==}
184
- engines: {node: '>=4'}
185
-
186
- url@0.11.4:
187
- resolution: {integrity: sha512-oCwdVC7mTuWiPyjLUz/COz5TLk6wgp0RCsN+wHZ2Ekneac9w8uuV0njcbbie2ME+Vs+d6duwmYuR3HgQXs1fOg==}
188
- engines: {node: '>= 0.4'}
189
-
190
- util@0.10.4:
191
- resolution: {integrity: sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==}
192
-
193
- snapshots:
194
-
195
- '@sinonjs/commons@3.0.1':
196
- dependencies:
197
- type-detect: 4.0.8
198
-
199
- '@sinonjs/fake-timers@15.1.0':
200
- dependencies:
201
- '@sinonjs/commons': 3.0.1
202
-
203
- '@sinonjs/samsam@8.0.3':
204
- dependencies:
205
- '@sinonjs/commons': 3.0.1
206
- type-detect: 4.1.0
207
-
208
- '@stonyx/utils@0.2.3-beta.4': {}
209
-
210
- call-bind-apply-helpers@1.0.2:
211
- dependencies:
212
- es-errors: 1.3.0
213
- function-bind: 1.1.2
214
-
215
- call-bound@1.0.4:
216
- dependencies:
217
- call-bind-apply-helpers: 1.0.2
218
- get-intrinsic: 1.3.0
219
-
220
- chalk@5.6.2: {}
221
-
222
- commander@7.2.0: {}
223
-
224
- diff@8.0.3: {}
225
-
226
- dunder-proto@1.0.1:
227
- dependencies:
228
- call-bind-apply-helpers: 1.0.2
229
- es-errors: 1.3.0
230
- gopd: 1.2.0
231
-
232
- es-define-property@1.0.1: {}
233
-
234
- es-errors@1.3.0: {}
235
-
236
- es-object-atoms@1.1.1:
237
- dependencies:
238
- es-errors: 1.3.0
239
-
240
- fs@0.0.1-security: {}
241
-
242
- function-bind@1.1.2: {}
243
-
244
- get-intrinsic@1.3.0:
245
- dependencies:
246
- call-bind-apply-helpers: 1.0.2
247
- es-define-property: 1.0.1
248
- es-errors: 1.3.0
249
- es-object-atoms: 1.1.1
250
- function-bind: 1.1.2
251
- get-proto: 1.0.1
252
- gopd: 1.2.0
253
- has-symbols: 1.1.0
254
- hasown: 2.0.2
255
- math-intrinsics: 1.1.0
256
-
257
- get-proto@1.0.1:
258
- dependencies:
259
- dunder-proto: 1.0.1
260
- es-object-atoms: 1.1.1
261
-
262
- globalyzer@0.1.0: {}
263
-
264
- globrex@0.1.2: {}
265
-
266
- gopd@1.2.0: {}
267
-
268
- has-flag@4.0.0: {}
269
-
270
- has-symbols@1.1.0: {}
271
-
272
- hasown@2.0.2:
273
- dependencies:
274
- function-bind: 1.1.2
275
-
276
- inherits@2.0.3: {}
277
-
278
- math-intrinsics@1.1.0: {}
279
-
280
- node-chronicle@0.2.0:
281
- dependencies:
282
- chalk: 5.6.2
283
- fs: 0.0.1-security
284
- path: 0.12.7
285
- url: 0.11.4
286
-
287
- node-watch@0.7.3: {}
288
-
289
- object-inspect@1.13.4: {}
290
-
291
- path@0.12.7:
292
- dependencies:
293
- process: 0.11.10
294
- util: 0.10.4
295
-
296
- process@0.11.10: {}
297
-
298
- punycode@1.4.1: {}
299
-
300
- qs@6.14.1:
301
- dependencies:
302
- side-channel: 1.1.0
303
-
304
- qunit@2.25.0:
305
- dependencies:
306
- commander: 7.2.0
307
- node-watch: 0.7.3
308
- tiny-glob: 0.2.9
309
-
310
- side-channel-list@1.0.0:
311
- dependencies:
312
- es-errors: 1.3.0
313
- object-inspect: 1.13.4
314
-
315
- side-channel-map@1.0.1:
316
- dependencies:
317
- call-bound: 1.0.4
318
- es-errors: 1.3.0
319
- get-intrinsic: 1.3.0
320
- object-inspect: 1.13.4
321
-
322
- side-channel-weakmap@1.0.2:
323
- dependencies:
324
- call-bound: 1.0.4
325
- es-errors: 1.3.0
326
- get-intrinsic: 1.3.0
327
- object-inspect: 1.13.4
328
- side-channel-map: 1.0.1
329
-
330
- side-channel@1.1.0:
331
- dependencies:
332
- es-errors: 1.3.0
333
- object-inspect: 1.13.4
334
- side-channel-list: 1.0.0
335
- side-channel-map: 1.0.1
336
- side-channel-weakmap: 1.0.2
337
-
338
- sinon@21.0.1:
339
- dependencies:
340
- '@sinonjs/commons': 3.0.1
341
- '@sinonjs/fake-timers': 15.1.0
342
- '@sinonjs/samsam': 8.0.3
343
- diff: 8.0.3
344
- supports-color: 7.2.0
345
-
346
- stonyx@0.2.3-beta.4:
347
- dependencies:
348
- node-chronicle: 0.2.0
349
-
350
- supports-color@7.2.0:
351
- dependencies:
352
- has-flag: 4.0.0
353
-
354
- tiny-glob@0.2.9:
355
- dependencies:
356
- globalyzer: 0.1.0
357
- globrex: 0.1.2
358
-
359
- type-detect@4.0.8: {}
360
-
361
- type-detect@4.1.0: {}
362
-
363
- url@0.11.4:
364
- dependencies:
365
- punycode: 1.4.1
366
- qs: 6.14.1
367
-
368
- util@0.10.4:
369
- dependencies:
370
- inherits: 2.0.3
package/src/main.js DELETED
@@ -1,112 +0,0 @@
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
-
17
- import config from 'stonyx/config';
18
- import log from 'stonyx/log';
19
- import { getTimestamp } from "@stonyx/utils/date";
20
- import MinHeap from '@stonyx/cron/min-heap';
21
-
22
- export default class Cron {
23
- jobs = {};
24
- heap = new MinHeap();
25
- timer = null;
26
-
27
- constructor() {
28
- if (Cron.instance) return Cron.instance;
29
- Cron.instance = this;
30
- }
31
-
32
- scheduleNextRun() {
33
- clearTimeout(this.timer);
34
-
35
- const { heap } = this;
36
-
37
- if (heap.isEmpty()) return;
38
-
39
- const nextJob = heap.peek();
40
- const delay = Math.max(0, nextJob.nextTrigger - getTimestamp()) * 1000;
41
-
42
- this.timer = setTimeout(() => this.runDueJobs(), delay);
43
- }
44
-
45
- async runDueJobs() {
46
- const now = getTimestamp();
47
- const { heap } = this;
48
-
49
- while (!heap.isEmpty() && heap.peek().nextTrigger <= now) {
50
- const job = heap.pop();
51
-
52
- if (config.debug) this.log('job has been triggered', job.key);
53
-
54
- try {
55
- await job.callback();
56
- } catch (err) {
57
- log.error(`Cron job "${job.key}" failed:`, err);
58
- }
59
-
60
- this.setNextTrigger(job);
61
- heap.push(job);
62
- }
63
-
64
- this.scheduleNextRun();
65
- }
66
-
67
- register(key, callback, interval, runOnInit=false) {
68
- const job = { callback, interval, key };
69
- this.jobs[key] = job;
70
- this.setNextTrigger(job);
71
- this.heap.push(job);
72
-
73
- if (config.debug) {
74
- this.log(`job has been registered with interval: ${interval}`, key);
75
- }
76
-
77
- if (runOnInit) {
78
- try {
79
- callback();
80
- } catch (err) {
81
- log.error(`Cron job "${key}" failed on init:`, err);
82
- }
83
- }
84
-
85
- this.scheduleNextRun();
86
- }
87
-
88
- unregister(key) {
89
- const { heap, jobs } = this;
90
- const job = jobs[key];
91
-
92
- if (!job) return;
93
-
94
- delete jobs[key];
95
- heap.remove(job);
96
-
97
- if (config.debug) this.log('job has been unregistered', key);
98
-
99
- this.scheduleNextRun();
100
- }
101
-
102
- setNextTrigger(job) {
103
- job.nextTrigger = getTimestamp() + parseInt(job.interval, 10);
104
- }
105
-
106
- log(text, key = null) {
107
- if (!config.cron?.log) return;
108
-
109
- const tag = key ? `Cron::${key}` : `Cron`;
110
- log.cron(`${tag} - ${text}:`);
111
- }
112
- }