worker-que 1.0.0 → 1.0.1

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.
@@ -0,0 +1,337 @@
1
+ # Contributing to worker-que
2
+
3
+ Thank you for your interest in contributing! This document provides guidelines and instructions for contributing to worker-que.
4
+
5
+ ## Getting Started
6
+
7
+ ### Prerequisites
8
+
9
+ - Node.js >= 16.0.0
10
+ - PostgreSQL >= 10
11
+ - Docker (optional, for development)
12
+
13
+ ### Setup Development Environment
14
+
15
+ 1. **Clone the repository**
16
+ ```bash
17
+ git clone https://github.com/your-username/worker-que.git
18
+ cd worker-que
19
+ ```
20
+
21
+ 2. **Install dependencies**
22
+ ```bash
23
+ npm install
24
+ ```
25
+
26
+ 3. **Start PostgreSQL (using Docker)**
27
+ ```bash
28
+ npm run docker:up
29
+ ```
30
+
31
+ 4. **Run tests**
32
+ ```bash
33
+ npm test
34
+ ```
35
+
36
+ 5. **Build the project**
37
+ ```bash
38
+ npm run build
39
+ ```
40
+
41
+ ## Development Workflow
42
+
43
+ ### Running Tests
44
+
45
+ ```bash
46
+ # Run all tests
47
+ npm test
48
+
49
+ # Run tests in watch mode
50
+ npm run test:watch
51
+
52
+ # Run tests with coverage
53
+ npm run test:coverage
54
+
55
+ # Run tests with debugging
56
+ npm run test:debug
57
+ ```
58
+
59
+ ### Building
60
+
61
+ ```bash
62
+ # Build TypeScript
63
+ npm run build
64
+
65
+ # Watch mode for development
66
+ npm run dev
67
+
68
+ # Clean build artifacts
69
+ npm run clean
70
+ ```
71
+
72
+ ### Linting
73
+
74
+ ```bash
75
+ # Run linter
76
+ npm run lint
77
+
78
+ # Fix linting errors
79
+ npm run lint:fix
80
+ ```
81
+
82
+ ## Project Structure
83
+
84
+ ```
85
+ worker-que/
86
+ ├── src/ # Source code
87
+ │ ├── client.ts # Client for enqueueing jobs
88
+ │ ├── worker.ts # Worker for processing jobs
89
+ │ ├── job.ts # Job instance class
90
+ │ ├── types.ts # TypeScript type definitions
91
+ │ ├── utils.ts # Utility functions
92
+ │ ├── sql.ts # SQL queries
93
+ │ └── dashboard/ # Dashboard module
94
+ │ ├── index.ts # Express router
95
+ │ ├── service.ts # Business logic
96
+ │ └── views.ts # HTML templates
97
+ ├── tests/ # Test files
98
+ ├── examples/ # Example applications
99
+ ├── migrations/ # SQL migrations
100
+ └── dist/ # Compiled JavaScript
101
+ ```
102
+
103
+ ## Making Changes
104
+
105
+ ### 1. Create a Branch
106
+
107
+ ```bash
108
+ git checkout -b feature/your-feature-name
109
+ # or
110
+ git checkout -b fix/your-bug-fix
111
+ ```
112
+
113
+ ### 2. Make Your Changes
114
+
115
+ - Write clean, readable code
116
+ - Follow existing code style
117
+ - Add tests for new features
118
+ - Update documentation as needed
119
+
120
+ ### 3. Run Tests
121
+
122
+ ```bash
123
+ npm test
124
+ npm run lint
125
+ ```
126
+
127
+ ### 4. Commit Your Changes
128
+
129
+ We follow [Conventional Commits](https://www.conventionalcommits.org/):
130
+
131
+ ```bash
132
+ # Features
133
+ git commit -m "feat: add new retry strategy"
134
+
135
+ # Bug fixes
136
+ git commit -m "fix: resolve connection pool leak"
137
+
138
+ # Documentation
139
+ git commit -m "docs: update dashboard setup guide"
140
+
141
+ # Tests
142
+ git commit -m "test: add tests for worker shutdown"
143
+ ```
144
+
145
+ ### 5. Push and Create Pull Request
146
+
147
+ ```bash
148
+ git push origin feature/your-feature-name
149
+ ```
150
+
151
+ Then create a pull request on GitHub.
152
+
153
+ ## Pull Request Guidelines
154
+
155
+ ### Before Submitting
156
+
157
+ - [ ] Tests pass locally
158
+ - [ ] Code is linted
159
+ - [ ] Documentation is updated
160
+ - [ ] Examples are updated (if applicable)
161
+ - [ ] CHANGELOG is updated (for notable changes)
162
+
163
+ ### Pull Request Template
164
+
165
+ ```markdown
166
+ ## Description
167
+ Brief description of changes
168
+
169
+ ## Type of Change
170
+ - [ ] Bug fix
171
+ - [ ] New feature
172
+ - [ ] Breaking change
173
+ - [ ] Documentation update
174
+
175
+ ## Testing
176
+ How have you tested these changes?
177
+
178
+ ## Checklist
179
+ - [ ] Tests pass
180
+ - [ ] Linting passes
181
+ - [ ] Documentation updated
182
+ - [ ] Examples updated
183
+ ```
184
+
185
+ ## Code Style
186
+
187
+ ### TypeScript
188
+
189
+ - Use TypeScript for all source files
190
+ - Provide proper type annotations
191
+ - Avoid `any` types when possible
192
+ - Use interfaces for public APIs
193
+
194
+ ### Naming Conventions
195
+
196
+ - **Classes**: PascalCase (`Client`, `Worker`)
197
+ - **Interfaces**: PascalCase (`ClientConfig`, `Job`)
198
+ - **Functions**: camelCase (`enqueue`, `lockJob`)
199
+ - **Constants**: UPPER_SNAKE_CASE (`SQL_QUERIES`)
200
+ - **Files**: kebab-case (`dashboard-service.ts`)
201
+
202
+ ### Code Organization
203
+
204
+ - Keep functions small and focused
205
+ - Use async/await over promises
206
+ - Handle errors appropriately
207
+ - Add JSDoc comments for public APIs
208
+
209
+ ### Example
210
+
211
+ ```typescript
212
+ /**
213
+ * Enqueues a new job to the queue
214
+ *
215
+ * @param jobClass - The job class name
216
+ * @param args - Job arguments as JSON array
217
+ * @param options - Enqueue options (priority, queue, runAt)
218
+ * @returns Promise resolving to the created job
219
+ */
220
+ async enqueue(
221
+ jobClass: string,
222
+ args: JSONArray = [],
223
+ options: EnqueueOptions = {}
224
+ ): Promise<Job> {
225
+ // Implementation
226
+ }
227
+ ```
228
+
229
+ ## Testing Guidelines
230
+
231
+ ### Test Structure
232
+
233
+ ```typescript
234
+ describe('Feature', () => {
235
+ beforeEach(async () => {
236
+ // Setup
237
+ });
238
+
239
+ afterEach(async () => {
240
+ // Cleanup
241
+ });
242
+
243
+ it('should do something', async () => {
244
+ // Arrange
245
+ const input = createTestData();
246
+
247
+ // Act
248
+ const result = await doSomething(input);
249
+
250
+ // Assert
251
+ expect(result).toBeDefined();
252
+ });
253
+ });
254
+ ```
255
+
256
+ ### Test Coverage
257
+
258
+ - Aim for >80% code coverage
259
+ - Test happy paths and error cases
260
+ - Test edge cases
261
+ - Test concurrent scenarios for workers
262
+
263
+ ### Running Specific Tests
264
+
265
+ ```bash
266
+ # Run specific file
267
+ npm test -- client.test.ts
268
+
269
+ # Run tests matching pattern
270
+ npm test -- --testNamePattern="should enqueue"
271
+ ```
272
+
273
+ ## Documentation
274
+
275
+ ### README Updates
276
+
277
+ - Keep README concise and focused
278
+ - Include working code examples
279
+ - Update badges if needed
280
+
281
+ ### API Documentation
282
+
283
+ - Document all public APIs with JSDoc
284
+ - Include parameter types and descriptions
285
+ - Provide usage examples
286
+ - Document return values and errors
287
+
288
+ ### Examples
289
+
290
+ - Keep examples simple and focused
291
+ - Make examples runnable
292
+ - Include comments explaining key concepts
293
+
294
+ ## Reporting Issues
295
+
296
+ ### Bug Reports
297
+
298
+ Include:
299
+ - Clear description of the issue
300
+ - Steps to reproduce
301
+ - Expected vs actual behavior
302
+ - Environment details (Node version, PostgreSQL version)
303
+ - Error messages and stack traces
304
+
305
+ ### Feature Requests
306
+
307
+ Include:
308
+ - Clear description of the feature
309
+ - Use cases and motivation
310
+ - Proposed API (if applicable)
311
+ - Alternatives considered
312
+
313
+ ## Release Process
314
+
315
+ (For maintainers)
316
+
317
+ 1. Update version in `package.json`
318
+ 2. Update CHANGELOG.md
319
+ 3. Commit changes
320
+ 4. Create git tag: `git tag v1.x.x`
321
+ 5. Push with tags: `git push --tags`
322
+ 6. Publish to npm: `npm publish`
323
+ 7. Create GitHub release
324
+
325
+ ## Questions?
326
+
327
+ - Open an issue for questions
328
+ - Join discussions on GitHub
329
+ - Check existing documentation
330
+
331
+ ## License
332
+
333
+ By contributing, you agree that your contributions will be licensed under the MIT License.
334
+
335
+ ---
336
+
337
+ Thank you for contributing to worker-que! 🎉