@stonyx/cron 0.1.0 → 0.2.1-alpha.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/project-structure.md +771 -0
- package/.git/config +18 -0
- package/.github/workflows/ci.yml +36 -0
- package/.github/workflows/publish.yml +143 -0
- package/.gitignore +3 -0
- package/.npmignore +5 -0
- package/README.md +45 -4
- package/logs/error.log +2 -0
- package/package.json +14 -9
- 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
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
|
-
});
|