worker-que 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.
Files changed (48) hide show
  1. package/DASHBOARD-QUICKSTART.md +278 -0
  2. package/DASHBOARD.md +556 -0
  3. package/LICENSE +21 -0
  4. package/README.md +414 -0
  5. package/SSL-QUICK-REFERENCE.md +225 -0
  6. package/SSL.md +516 -0
  7. package/dist/client.d.ts +11 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +64 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/dashboard/index.d.ts +34 -0
  12. package/dist/dashboard/index.d.ts.map +1 -0
  13. package/dist/dashboard/index.js +164 -0
  14. package/dist/dashboard/index.js.map +1 -0
  15. package/dist/dashboard/service.d.ts +66 -0
  16. package/dist/dashboard/service.d.ts.map +1 -0
  17. package/dist/dashboard/service.js +201 -0
  18. package/dist/dashboard/service.js.map +1 -0
  19. package/dist/dashboard/views.d.ts +3 -0
  20. package/dist/dashboard/views.d.ts.map +1 -0
  21. package/dist/dashboard/views.js +786 -0
  22. package/dist/dashboard/views.js.map +1 -0
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +29 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/job.d.ts +19 -0
  28. package/dist/job.d.ts.map +1 -0
  29. package/dist/job.js +36 -0
  30. package/dist/job.js.map +1 -0
  31. package/dist/sql.d.ts +8 -0
  32. package/dist/sql.d.ts.map +1 -0
  33. package/dist/sql.js +57 -0
  34. package/dist/sql.js.map +1 -0
  35. package/dist/types.d.ts +90 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +3 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/utils.d.ts +6 -0
  40. package/dist/utils.d.ts.map +1 -0
  41. package/dist/utils.js +31 -0
  42. package/dist/utils.js.map +1 -0
  43. package/dist/worker.d.ts +19 -0
  44. package/dist/worker.d.ts.map +1 -0
  45. package/dist/worker.js +99 -0
  46. package/dist/worker.js.map +1 -0
  47. package/migrations/schema.sql +26 -0
  48. package/package.json +105 -0
@@ -0,0 +1,278 @@
1
+ # Dashboard Quick Start Guide
2
+
3
+ Get your Que dashboard up and running in 5 minutes!
4
+
5
+ ## Prerequisites
6
+
7
+ - Node.js 16+ installed
8
+ - PostgreSQL database with `que_jobs` table
9
+ - Express.js installed
10
+
11
+ ## Step 1: Install Dependencies
12
+
13
+ ```bash
14
+ npm install que-ts express
15
+ npm install --save-dev @types/express # If using TypeScript
16
+ ```
17
+
18
+ ## Step 2: Create Dashboard Server
19
+
20
+ Create a file `dashboard.js` (or `dashboard.ts`):
21
+
22
+ ```javascript
23
+ const express = require('express');
24
+ const { Pool } = require('pg');
25
+ const { createDashboard } = require('que-ts/dashboard');
26
+
27
+ const app = express();
28
+ const pool = new Pool({
29
+ host: 'localhost',
30
+ port: 5432,
31
+ database: 'your_database',
32
+ user: 'your_user',
33
+ password: 'your_password',
34
+ });
35
+
36
+ // Mount dashboard
37
+ app.use('/queue', createDashboard(pool, {
38
+ title: 'My Queue Dashboard',
39
+ refreshInterval: 3000, // Refresh every 3 seconds
40
+ }));
41
+
42
+ const PORT = process.env.PORT || 3000;
43
+ app.listen(PORT, () => {
44
+ console.log(`Dashboard running at http://localhost:${PORT}/queue`);
45
+ });
46
+ ```
47
+
48
+ ## Step 3: Run the Server
49
+
50
+ ```bash
51
+ node dashboard.js
52
+ ```
53
+
54
+ ## Step 4: Open in Browser
55
+
56
+ Visit http://localhost:3000/queue
57
+
58
+ You should see:
59
+ - 📊 Real-time job statistics
60
+ - 📈 Charts showing distribution by queue and class
61
+ - 📋 Paginated job list with filters
62
+ - ⚠️ Recent failures section
63
+
64
+ ## Step 5: Add Authentication (Production)
65
+
66
+ For production, always add authentication:
67
+
68
+ ```javascript
69
+ app.use('/queue', createDashboard(pool, {
70
+ title: 'Production Queue',
71
+ auth: (req, res, next) => {
72
+ // Check API key
73
+ const apiKey = req.headers['x-api-key'];
74
+ if (apiKey === process.env.DASHBOARD_API_KEY) {
75
+ return true;
76
+ }
77
+
78
+ // Or check session
79
+ if (req.session?.user?.isAdmin) {
80
+ return true;
81
+ }
82
+
83
+ return false; // Deny access
84
+ }
85
+ }));
86
+ ```
87
+
88
+ ## TypeScript Version
89
+
90
+ If using TypeScript:
91
+
92
+ ```typescript
93
+ import express from 'express';
94
+ import { Pool } from 'pg';
95
+ import { createDashboard } from 'que-ts/dashboard';
96
+
97
+ const app = express();
98
+ const pool = new Pool({
99
+ host: 'localhost',
100
+ port: 5432,
101
+ database: 'your_database',
102
+ user: 'your_user',
103
+ password: 'your_password',
104
+ });
105
+
106
+ app.use('/queue', createDashboard(pool, {
107
+ title: 'My Queue Dashboard',
108
+ refreshInterval: 3000,
109
+ }));
110
+
111
+ const PORT = process.env.PORT || 3000;
112
+ app.listen(PORT, () => {
113
+ console.log(`Dashboard: http://localhost:${PORT}/queue`);
114
+ });
115
+ ```
116
+
117
+ ## Complete Example with Worker
118
+
119
+ ```typescript
120
+ import express from 'express';
121
+ import { Pool } from 'pg';
122
+ import { createDashboard } from 'que-ts/dashboard';
123
+ import { Client, Worker } from 'que-ts';
124
+
125
+ const dbConfig = {
126
+ host: 'localhost',
127
+ port: 5432,
128
+ database: 'myapp',
129
+ user: 'postgres',
130
+ password: 'password',
131
+ };
132
+
133
+ // Create Express app
134
+ const app = express();
135
+ const pool = new Pool(dbConfig);
136
+
137
+ // Add dashboard
138
+ app.use('/admin/queue', createDashboard(pool, {
139
+ title: 'My App Queue',
140
+ refreshInterval: 2000,
141
+ }));
142
+
143
+ // Create worker
144
+ const worker = new Worker(dbConfig, { interval: 1000 });
145
+
146
+ worker.register('SendEmail', async (job) => {
147
+ const [emailData] = job.args;
148
+ console.log(`Sending email to ${emailData.to}`);
149
+ // Your email logic here
150
+ });
151
+
152
+ worker.register('ProcessPayment', async (job) => {
153
+ const [paymentData] = job.args;
154
+ console.log(`Processing payment: $${paymentData.amount}`);
155
+ // Your payment logic here
156
+ });
157
+
158
+ // Start server and worker
159
+ const PORT = 3000;
160
+ app.listen(PORT, () => {
161
+ console.log(`Server: http://localhost:${PORT}`);
162
+ console.log(`Dashboard: http://localhost:${PORT}/admin/queue`);
163
+
164
+ // Start worker
165
+ worker.work().catch(console.error);
166
+ });
167
+
168
+ // Graceful shutdown
169
+ process.on('SIGINT', async () => {
170
+ await worker.shutdown();
171
+ await pool.end();
172
+ process.exit(0);
173
+ });
174
+ ```
175
+
176
+ ## Troubleshooting
177
+
178
+ ### "Cannot find module 'que-ts/dashboard'"
179
+
180
+ Make sure you're importing from the compiled distribution:
181
+
182
+ ```javascript
183
+ // CommonJS
184
+ const { createDashboard } = require('que-ts/dist/dashboard');
185
+
186
+ // ES6
187
+ import { createDashboard } from 'que-ts/dist/dashboard';
188
+ ```
189
+
190
+ Or update your package.json exports (for library authors).
191
+
192
+ ### Dashboard shows no data
193
+
194
+ 1. Check that `que_jobs` table exists
195
+ 2. Verify database connection is working
196
+ 3. Check browser console for errors
197
+ 4. Verify API routes are accessible (try `/queue/api/stats`)
198
+
199
+ ### Authentication not working
200
+
201
+ 1. Make sure auth function returns boolean (true/false)
202
+ 2. For async auth, declare function as `async`
203
+ 3. Check browser console for 403 errors
204
+
205
+ ## Next Steps
206
+
207
+ - Read the full [DASHBOARD.md](DASHBOARD.md) documentation
208
+ - Explore API routes for programmatic access
209
+ - Add custom authentication
210
+ - Configure for production deployment
211
+
212
+ ## Environment Variables
213
+
214
+ For production, use environment variables:
215
+
216
+ ```bash
217
+ # .env
218
+ DB_HOST=localhost
219
+ DB_PORT=5432
220
+ DB_NAME=myapp
221
+ DB_USER=postgres
222
+ DB_PASSWORD=secret
223
+ DASHBOARD_PATH=/admin/queue
224
+ DASHBOARD_TITLE=Production Queue
225
+ DASHBOARD_REFRESH_MS=5000
226
+ DASHBOARD_API_KEY=your-secret-key
227
+ ```
228
+
229
+ ```javascript
230
+ require('dotenv').config();
231
+
232
+ const pool = new Pool({
233
+ host: process.env.DB_HOST,
234
+ port: parseInt(process.env.DB_PORT),
235
+ database: process.env.DB_NAME,
236
+ user: process.env.DB_USER,
237
+ password: process.env.DB_PASSWORD,
238
+ });
239
+
240
+ app.use(process.env.DASHBOARD_PATH, createDashboard(pool, {
241
+ title: process.env.DASHBOARD_TITLE,
242
+ refreshInterval: parseInt(process.env.DASHBOARD_REFRESH_MS),
243
+ auth: (req) => req.headers['x-api-key'] === process.env.DASHBOARD_API_KEY
244
+ }));
245
+ ```
246
+
247
+ ## Docker Deployment
248
+
249
+ ```dockerfile
250
+ FROM node:18-alpine
251
+
252
+ WORKDIR /app
253
+ COPY package*.json ./
254
+ RUN npm ci --only=production
255
+
256
+ COPY . .
257
+
258
+ ENV NODE_ENV=production
259
+ ENV PORT=3000
260
+
261
+ EXPOSE 3000
262
+
263
+ CMD ["node", "dashboard.js"]
264
+ ```
265
+
266
+ ```bash
267
+ docker build -t my-queue-dashboard .
268
+ docker run -p 3000:3000 \
269
+ -e DB_HOST=postgres \
270
+ -e DB_NAME=myapp \
271
+ -e DB_USER=postgres \
272
+ -e DB_PASSWORD=secret \
273
+ my-queue-dashboard
274
+ ```
275
+
276
+ ---
277
+
278
+ **Need Help?** Check the full documentation at [DASHBOARD.md](DASHBOARD.md)