nodejs-task-scheduler 1.0.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 +20 -0
- package/.github/workflows/ci.yml +266 -0
- package/.github/workflows/release.yml +117 -0
- package/CHANGELOG.md +43 -0
- package/README.md +653 -0
- package/dist/__tests__/setup.d.ts +2 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +24 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/decorators/index.d.ts +80 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +171 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/metadata.d.ts +59 -0
- package/dist/decorators/metadata.d.ts.map +1 -0
- package/dist/decorators/metadata.js +68 -0
- package/dist/decorators/metadata.js.map +1 -0
- package/dist/decorators/registry.d.ts +42 -0
- package/dist/decorators/registry.d.ts.map +1 -0
- package/dist/decorators/registry.js +182 -0
- package/dist/decorators/registry.js.map +1 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +198 -0
- package/dist/index.js.map +1 -0
- package/dist/queue/index.d.ts +19 -0
- package/dist/queue/index.d.ts.map +1 -0
- package/dist/queue/index.js +89 -0
- package/dist/queue/index.js.map +1 -0
- package/dist/scheduler/index.d.ts +13 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +102 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/types/index.d.ts +63 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/load-balancer.d.ts +36 -0
- package/dist/utils/load-balancer.d.ts.map +1 -0
- package/dist/utils/load-balancer.js +158 -0
- package/dist/utils/load-balancer.js.map +1 -0
- package/dist/utils/rabbitmq.d.ts +18 -0
- package/dist/utils/rabbitmq.d.ts.map +1 -0
- package/dist/utils/rabbitmq.js +114 -0
- package/dist/utils/rabbitmq.js.map +1 -0
- package/dist/worker/index.d.ts +20 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +138 -0
- package/dist/worker/index.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(mkdir:*)",
|
|
5
|
+
"Bash(npm run build:*)",
|
|
6
|
+
"Bash(npm ls:*)",
|
|
7
|
+
"Bash(npm install:*)",
|
|
8
|
+
"Bash(npm run dev:*)",
|
|
9
|
+
"Bash(npx ts-node:*)",
|
|
10
|
+
"Bash(rm:*)",
|
|
11
|
+
"Bash(npm run lint)",
|
|
12
|
+
"Bash(npm run:*)",
|
|
13
|
+
"Bash(npm test)",
|
|
14
|
+
"Bash(npm test:*)",
|
|
15
|
+
"Bash(node:*)",
|
|
16
|
+
"Bash(touch:*)"
|
|
17
|
+
],
|
|
18
|
+
"deny": []
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
name: CI/CD Pipeline
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master, develop ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
release:
|
|
9
|
+
types: [ published ]
|
|
10
|
+
|
|
11
|
+
env:
|
|
12
|
+
NODE_VERSION: '22.x'
|
|
13
|
+
REGISTRY: ghcr.io
|
|
14
|
+
IMAGE_NAME: ${{ github.repository }}
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
test:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
|
|
20
|
+
services:
|
|
21
|
+
rabbitmq:
|
|
22
|
+
image: rabbitmq:3-management
|
|
23
|
+
ports:
|
|
24
|
+
- 5672:5672
|
|
25
|
+
- 15672:15672
|
|
26
|
+
env:
|
|
27
|
+
RABBITMQ_DEFAULT_USER: admin
|
|
28
|
+
RABBITMQ_DEFAULT_PASS: password
|
|
29
|
+
options: >-
|
|
30
|
+
--health-cmd "rabbitmq-diagnostics -q ping"
|
|
31
|
+
--health-interval 30s
|
|
32
|
+
--health-timeout 30s
|
|
33
|
+
--health-retries 3
|
|
34
|
+
|
|
35
|
+
strategy:
|
|
36
|
+
matrix:
|
|
37
|
+
node-version: [16.x, 18.x, 20.x, 22.x]
|
|
38
|
+
|
|
39
|
+
steps:
|
|
40
|
+
- name: Checkout code
|
|
41
|
+
uses: actions/checkout@v4
|
|
42
|
+
|
|
43
|
+
- name: Setup Node.js ${{ matrix.node-version }}
|
|
44
|
+
uses: actions/setup-node@v4
|
|
45
|
+
with:
|
|
46
|
+
node-version: ${{ matrix.node-version }}
|
|
47
|
+
cache: 'npm'
|
|
48
|
+
|
|
49
|
+
- name: Install dependencies
|
|
50
|
+
run: npm ci
|
|
51
|
+
|
|
52
|
+
- name: Run linter
|
|
53
|
+
run: npm run lint
|
|
54
|
+
continue-on-error: true
|
|
55
|
+
|
|
56
|
+
- name: Build TypeScript
|
|
57
|
+
run: npm run build
|
|
58
|
+
|
|
59
|
+
- name: Run tests
|
|
60
|
+
run: npm test -- --maxWorkers=1 --forceExit
|
|
61
|
+
env:
|
|
62
|
+
RABBITMQ_URL: amqp://admin:password@localhost:5672
|
|
63
|
+
NODE_OPTIONS: "--max_old_space_size=4096"
|
|
64
|
+
|
|
65
|
+
- name: Upload coverage reports
|
|
66
|
+
uses: codecov/codecov-action@v3
|
|
67
|
+
if: matrix.node-version == '18.x'
|
|
68
|
+
continue-on-error: true
|
|
69
|
+
|
|
70
|
+
publish-npm:
|
|
71
|
+
needs: test
|
|
72
|
+
runs-on: ubuntu-latest
|
|
73
|
+
if: github.event_name == 'release'
|
|
74
|
+
|
|
75
|
+
steps:
|
|
76
|
+
- name: Checkout code
|
|
77
|
+
uses: actions/checkout@v4
|
|
78
|
+
|
|
79
|
+
- name: Setup Node.js
|
|
80
|
+
uses: actions/setup-node@v4
|
|
81
|
+
with:
|
|
82
|
+
node-version: ${{ env.NODE_VERSION }}
|
|
83
|
+
cache: 'npm'
|
|
84
|
+
registry-url: 'https://registry.npmjs.org/'
|
|
85
|
+
|
|
86
|
+
- name: Install dependencies
|
|
87
|
+
run: npm ci
|
|
88
|
+
|
|
89
|
+
- name: Build package
|
|
90
|
+
run: npm run build
|
|
91
|
+
|
|
92
|
+
- name: Update version from release tag
|
|
93
|
+
run: |
|
|
94
|
+
VERSION="${{ github.event.release.tag_name }}"
|
|
95
|
+
VERSION=${VERSION#v} # Remove 'v' prefix if present
|
|
96
|
+
npm version "$VERSION" --no-git-tag-version
|
|
97
|
+
|
|
98
|
+
- name: Publish to NPM
|
|
99
|
+
run: npm publish
|
|
100
|
+
env:
|
|
101
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
102
|
+
|
|
103
|
+
publish-github:
|
|
104
|
+
needs: test
|
|
105
|
+
runs-on: ubuntu-latest
|
|
106
|
+
if: github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
|
|
107
|
+
|
|
108
|
+
permissions:
|
|
109
|
+
contents: read
|
|
110
|
+
packages: write
|
|
111
|
+
|
|
112
|
+
steps:
|
|
113
|
+
- name: Checkout code
|
|
114
|
+
uses: actions/checkout@v4
|
|
115
|
+
|
|
116
|
+
- name: Setup Node.js
|
|
117
|
+
uses: actions/setup-node@v4
|
|
118
|
+
with:
|
|
119
|
+
node-version: ${{ env.NODE_VERSION }}
|
|
120
|
+
cache: 'npm'
|
|
121
|
+
registry-url: 'https://npm.pkg.github.com'
|
|
122
|
+
|
|
123
|
+
- name: Install dependencies
|
|
124
|
+
run: npm ci
|
|
125
|
+
|
|
126
|
+
- name: Build package
|
|
127
|
+
run: npm run build
|
|
128
|
+
|
|
129
|
+
- name: Update package.json for scoped publishing
|
|
130
|
+
run: |
|
|
131
|
+
# Update package name for GitHub Packages
|
|
132
|
+
sed -i 's/"name": "nodejs-task-scheduler"/"name": "@${{ github.repository_owner }}\/nodejs-task-scheduler"/' package.json
|
|
133
|
+
|
|
134
|
+
# Update version if this is a release
|
|
135
|
+
if [ "${{ github.event_name }}" = "release" ]; then
|
|
136
|
+
VERSION="${{ github.event.release.tag_name }}"
|
|
137
|
+
VERSION=${VERSION#v} # Remove 'v' prefix if present
|
|
138
|
+
npm version "$VERSION" --no-git-tag-version
|
|
139
|
+
fi
|
|
140
|
+
|
|
141
|
+
- name: Create tarball
|
|
142
|
+
run: npm pack
|
|
143
|
+
|
|
144
|
+
- name: Publish to GitHub Packages
|
|
145
|
+
run: npm publish
|
|
146
|
+
env:
|
|
147
|
+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
148
|
+
|
|
149
|
+
- name: Upload build artifacts
|
|
150
|
+
uses: actions/upload-artifact@v4
|
|
151
|
+
with:
|
|
152
|
+
name: dist-files
|
|
153
|
+
path: |
|
|
154
|
+
dist/
|
|
155
|
+
*.tgz
|
|
156
|
+
retention-days: 30
|
|
157
|
+
|
|
158
|
+
create-docker-image:
|
|
159
|
+
needs: test
|
|
160
|
+
runs-on: ubuntu-latest
|
|
161
|
+
if: github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
|
|
162
|
+
|
|
163
|
+
permissions:
|
|
164
|
+
contents: read
|
|
165
|
+
packages: write
|
|
166
|
+
|
|
167
|
+
steps:
|
|
168
|
+
- name: Checkout code
|
|
169
|
+
uses: actions/checkout@v4
|
|
170
|
+
|
|
171
|
+
- name: Log in to Container Registry
|
|
172
|
+
uses: docker/login-action@v3
|
|
173
|
+
with:
|
|
174
|
+
registry: ${{ env.REGISTRY }}
|
|
175
|
+
username: ${{ github.actor }}
|
|
176
|
+
password: ${{ secrets.GITHUB_TOKEN }}
|
|
177
|
+
|
|
178
|
+
- name: Extract metadata
|
|
179
|
+
id: meta
|
|
180
|
+
uses: docker/metadata-action@v5
|
|
181
|
+
with:
|
|
182
|
+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
183
|
+
tags: |
|
|
184
|
+
type=ref,event=branch
|
|
185
|
+
type=ref,event=pr
|
|
186
|
+
type=semver,pattern={{version}}
|
|
187
|
+
type=semver,pattern={{major}}.{{minor}}
|
|
188
|
+
type=semver,pattern={{major}}
|
|
189
|
+
type=raw,value=latest,enable={{is_default_branch}}
|
|
190
|
+
|
|
191
|
+
- name: Build and push Docker image
|
|
192
|
+
uses: docker/build-push-action@v5
|
|
193
|
+
with:
|
|
194
|
+
context: .
|
|
195
|
+
push: true
|
|
196
|
+
tags: ${{ steps.meta.outputs.tags }}
|
|
197
|
+
labels: ${{ steps.meta.outputs.labels }}
|
|
198
|
+
cache-from: type=gha
|
|
199
|
+
cache-to: type=gha,mode=max
|
|
200
|
+
|
|
201
|
+
security-scan:
|
|
202
|
+
runs-on: ubuntu-latest
|
|
203
|
+
if: github.event_name == 'push' || github.event_name == 'pull_request'
|
|
204
|
+
|
|
205
|
+
permissions:
|
|
206
|
+
contents: read
|
|
207
|
+
security-events: write
|
|
208
|
+
|
|
209
|
+
steps:
|
|
210
|
+
- name: Checkout code
|
|
211
|
+
uses: actions/checkout@v4
|
|
212
|
+
|
|
213
|
+
- name: Setup Node.js
|
|
214
|
+
uses: actions/setup-node@v4
|
|
215
|
+
with:
|
|
216
|
+
node-version: ${{ env.NODE_VERSION }}
|
|
217
|
+
cache: 'npm'
|
|
218
|
+
|
|
219
|
+
- name: Install dependencies
|
|
220
|
+
run: npm ci
|
|
221
|
+
|
|
222
|
+
- name: Run security audit
|
|
223
|
+
run: npm audit --audit-level high
|
|
224
|
+
continue-on-error: true
|
|
225
|
+
|
|
226
|
+
- name: Run CodeQL Analysis
|
|
227
|
+
uses: github/codeql-action/init@v3
|
|
228
|
+
with:
|
|
229
|
+
languages: typescript
|
|
230
|
+
|
|
231
|
+
- name: Perform CodeQL Analysis
|
|
232
|
+
uses: github/codeql-action/analyze@v3
|
|
233
|
+
|
|
234
|
+
generate-docs:
|
|
235
|
+
runs-on: ubuntu-latest
|
|
236
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
237
|
+
|
|
238
|
+
permissions:
|
|
239
|
+
contents: write
|
|
240
|
+
pages: write
|
|
241
|
+
id-token: write
|
|
242
|
+
|
|
243
|
+
steps:
|
|
244
|
+
- name: Checkout code
|
|
245
|
+
uses: actions/checkout@v4
|
|
246
|
+
|
|
247
|
+
- name: Setup Node.js
|
|
248
|
+
uses: actions/setup-node@v4
|
|
249
|
+
with:
|
|
250
|
+
node-version: ${{ env.NODE_VERSION }}
|
|
251
|
+
cache: 'npm'
|
|
252
|
+
|
|
253
|
+
- name: Install dependencies
|
|
254
|
+
run: npm ci
|
|
255
|
+
|
|
256
|
+
- name: Generate TypeDoc documentation
|
|
257
|
+
run: |
|
|
258
|
+
npx typedoc src/index.ts --out docs --theme default
|
|
259
|
+
continue-on-error: true
|
|
260
|
+
|
|
261
|
+
- name: Deploy to GitHub Pages
|
|
262
|
+
uses: peaceiris/actions-gh-pages@v3
|
|
263
|
+
if: success()
|
|
264
|
+
with:
|
|
265
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
266
|
+
publish_dir: ./docs
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
env:
|
|
9
|
+
NODE_VERSION: '22.x'
|
|
10
|
+
REGISTRY: ghcr.io
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
create-release:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: write
|
|
18
|
+
packages: write
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout code
|
|
22
|
+
uses: actions/checkout@v4
|
|
23
|
+
with:
|
|
24
|
+
fetch-depth: 0
|
|
25
|
+
|
|
26
|
+
- name: Setup Node.js
|
|
27
|
+
uses: actions/setup-node@v4
|
|
28
|
+
with:
|
|
29
|
+
node-version: ${{ env.NODE_VERSION }}
|
|
30
|
+
cache: 'npm'
|
|
31
|
+
|
|
32
|
+
- name: Install dependencies
|
|
33
|
+
run: npm ci
|
|
34
|
+
|
|
35
|
+
- name: Build package
|
|
36
|
+
run: npm run build
|
|
37
|
+
|
|
38
|
+
- name: Run tests
|
|
39
|
+
run: npm test
|
|
40
|
+
continue-on-error: true
|
|
41
|
+
|
|
42
|
+
- name: Create package tarball
|
|
43
|
+
run: npm pack
|
|
44
|
+
|
|
45
|
+
- name: Generate changelog
|
|
46
|
+
id: changelog
|
|
47
|
+
run: |
|
|
48
|
+
if [ -f CHANGELOG.md ]; then
|
|
49
|
+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
|
|
50
|
+
cat CHANGELOG.md >> $GITHUB_OUTPUT
|
|
51
|
+
echo "EOF" >> $GITHUB_OUTPUT
|
|
52
|
+
else
|
|
53
|
+
echo "changelog=No changelog available" >> $GITHUB_OUTPUT
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
- name: Create GitHub Release
|
|
57
|
+
uses: softprops/action-gh-release@v1
|
|
58
|
+
with:
|
|
59
|
+
body: |
|
|
60
|
+
## Release ${{ github.ref_name }}
|
|
61
|
+
|
|
62
|
+
### Changes
|
|
63
|
+
${{ steps.changelog.outputs.changelog }}
|
|
64
|
+
|
|
65
|
+
### Installation
|
|
66
|
+
|
|
67
|
+
#### From GitHub Packages:
|
|
68
|
+
```bash
|
|
69
|
+
npm install @${{ github.repository_owner }}/nodejs-task-scheduler@${{ github.ref_name }}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### From source:
|
|
73
|
+
```bash
|
|
74
|
+
git clone https://github.com/${{ github.repository }}.git
|
|
75
|
+
cd nodejs-task-scheduler
|
|
76
|
+
git checkout ${{ github.ref_name }}
|
|
77
|
+
npm install && npm run build
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Docker Image
|
|
81
|
+
```bash
|
|
82
|
+
docker pull ghcr.io/${{ github.repository }}:${{ github.ref_name }}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
files: |
|
|
86
|
+
*.tgz
|
|
87
|
+
dist/**/*
|
|
88
|
+
generate_release_notes: true
|
|
89
|
+
draft: false
|
|
90
|
+
prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'rc') }}
|
|
91
|
+
|
|
92
|
+
- name: Publish to GitHub Packages
|
|
93
|
+
run: |
|
|
94
|
+
# Update package.json for scoped publishing
|
|
95
|
+
sed -i 's/"name": "nodejs-task-scheduler"/"name": "@${{ github.repository_owner }}\/nodejs-task-scheduler"/' package.json
|
|
96
|
+
|
|
97
|
+
# Set version from git tag
|
|
98
|
+
VERSION="${{ github.ref_name }}"
|
|
99
|
+
VERSION=${VERSION#v} # Remove 'v' prefix if present
|
|
100
|
+
npm version "$VERSION" --no-git-tag-version
|
|
101
|
+
|
|
102
|
+
# Publish
|
|
103
|
+
npm publish
|
|
104
|
+
env:
|
|
105
|
+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
106
|
+
|
|
107
|
+
notify-success:
|
|
108
|
+
needs: create-release
|
|
109
|
+
runs-on: ubuntu-latest
|
|
110
|
+
if: success()
|
|
111
|
+
|
|
112
|
+
steps:
|
|
113
|
+
- name: Notify success
|
|
114
|
+
run: |
|
|
115
|
+
echo "✅ Release ${{ github.ref_name }} created successfully!"
|
|
116
|
+
echo "📦 Package published to GitHub Packages"
|
|
117
|
+
echo "🐳 Docker image available at ghcr.io/${{ github.repository }}:${{ github.ref_name }}"
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of nodejs-task-scheduler
|
|
12
|
+
- Distributed task processing using RabbitMQ
|
|
13
|
+
- Cron job scheduling with timezone support
|
|
14
|
+
- Load balancing across multiple nodes
|
|
15
|
+
- Singleton and multi-instance worker support
|
|
16
|
+
- Automatic retry logic with exponential backoff
|
|
17
|
+
- Dead letter queue for failed jobs
|
|
18
|
+
- TypeScript support with full type definitions
|
|
19
|
+
- Comprehensive examples and documentation
|
|
20
|
+
- Docker support with Docker Compose setup
|
|
21
|
+
- GitHub Actions CI/CD pipeline
|
|
22
|
+
- Automatic package publishing to GitHub Packages
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
- `TaskScheduler` - Main API class for managing distributed tasks
|
|
26
|
+
- `JobScheduler` - Handles cron and direct job scheduling
|
|
27
|
+
- `JobWorker` - Processes jobs with configurable concurrency
|
|
28
|
+
- `QueueManager` - Manages RabbitMQ queues and exchanges
|
|
29
|
+
- `LoadBalancer` - Distributes jobs across available nodes
|
|
30
|
+
- `RabbitMQConnection` - Connection management with auto-reconnect
|
|
31
|
+
|
|
32
|
+
### Documentation
|
|
33
|
+
- Comprehensive README with usage examples
|
|
34
|
+
- API documentation
|
|
35
|
+
- Docker setup instructions
|
|
36
|
+
- Multi-node deployment examples
|
|
37
|
+
- Email service implementation example
|
|
38
|
+
- Basic usage examples
|
|
39
|
+
|
|
40
|
+
## [1.0.0] - TBD
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
- Initial stable release
|