Skip to content

Commit 0425319

Browse files
committed
chore: wip
1 parent bb43ab4 commit 0425319

File tree

25 files changed

+5356
-58
lines changed

25 files changed

+5356
-58
lines changed

config/queue.ts

Lines changed: 118 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,138 @@
11
import type { QueueConfig } from '@stacksjs/types'
2+
import { env } from '@stacksjs/env'
23

34
/**
4-
* **Queue Options**
5+
* **Queue Configuration**
56
*
6-
* This configuration defines all of your search engine options. Because Stacks is fully-typed,
7-
* you may hover any of the options below and the definitions will be provided. In case
8-
* you have any questions, feel free to reach out via Discord or GitHub Discussions.
7+
* This configuration defines all of your queue options. Stacks supports multiple
8+
* queue drivers including sync (immediate execution), database, Redis (via bun-queue),
9+
* and SQS.
10+
*
11+
* The Redis driver (powered by bun-queue) offers advanced features like:
12+
* - Distributed locks for job processing
13+
* - Horizontal scaling with leader election
14+
* - Rate limiting
15+
* - Dead letter queues
16+
* - Job priorities
17+
* - Cron scheduling
18+
* - Metrics collection
19+
*
20+
* Because Stacks is fully-typed, you may hover any of the options below and the
21+
* definitions will be provided.
922
*/
1023
export default {
11-
default: 'sync',
24+
// Default queue driver: 'sync' | 'database' | 'redis' | 'sqs' | 'memory'
25+
default: env.QUEUE_DRIVER || 'sync',
1226

1327
connections: {
28+
// Sync driver - executes jobs immediately (good for development)
1429
sync: {
1530
driver: 'sync',
1631
},
1732

18-
// database: {
19-
// driver: 'database',
20-
// table: 'jobs',
21-
// queue: 'default',
22-
// },
33+
// Database driver - stores jobs in the database
34+
database: {
35+
driver: 'database',
36+
table: 'jobs',
37+
queue: 'default',
38+
retryAfter: 90,
39+
},
2340

24-
// redis: {
25-
// driver: 'redis',
26-
// connection: 'default',
27-
// queue: 'default',
28-
// },
41+
// Redis driver (powered by bun-queue) - high-performance Redis-backed queue
42+
redis: {
43+
driver: 'redis',
44+
// Redis connection settings
45+
redis: {
46+
url: env.REDIS_URL,
47+
host: env.REDIS_HOST || 'localhost',
48+
port: env.REDIS_PORT || 6379,
49+
password: env.REDIS_PASSWORD,
50+
db: env.REDIS_DB || 0,
51+
},
52+
// Key prefix for all queue keys
53+
prefix: env.QUEUE_PREFIX || 'stacks:queue',
54+
// Worker concurrency (number of jobs processed simultaneously)
55+
concurrency: env.QUEUE_CONCURRENCY || 5,
56+
// Log level for queue operations
57+
logLevel: env.QUEUE_LOG_LEVEL || 'info',
58+
// Enable distributed locking for job processing
59+
distributedLock: true,
60+
// Stalled job check interval (ms)
61+
stalledJobCheckInterval: 30000,
62+
// Maximum retries for stalled jobs
63+
maxStalledJobRetries: 3,
64+
// Rate limiting configuration
65+
limiter: env.QUEUE_RATE_LIMIT_ENABLED ? {
66+
max: env.QUEUE_RATE_LIMIT_MAX || 100,
67+
duration: env.QUEUE_RATE_LIMIT_DURATION || 1000,
68+
} : undefined,
69+
// Metrics collection
70+
metrics: {
71+
enabled: env.QUEUE_METRICS_ENABLED || false,
72+
collectInterval: 10000,
73+
},
74+
// Dead letter queue for failed jobs
75+
defaultDeadLetterOptions: {
76+
enabled: env.QUEUE_DLQ_ENABLED || true,
77+
maxRetries: env.QUEUE_DLQ_MAX_RETRIES || 3,
78+
queueSuffix: '-dead-letter',
79+
},
80+
// Horizontal scaling (for multi-instance deployments)
81+
horizontalScaling: env.QUEUE_HORIZONTAL_SCALING_ENABLED ? {
82+
enabled: true,
83+
maxWorkersPerInstance: env.QUEUE_MAX_WORKERS || 10,
84+
jobsPerWorker: env.QUEUE_JOBS_PER_WORKER || 10,
85+
leaderElection: {
86+
heartbeatInterval: 5000,
87+
leaderTimeout: 15000,
88+
},
89+
} : undefined,
90+
// Default job options
91+
defaultJobOptions: {
92+
attempts: 3,
93+
removeOnComplete: true,
94+
removeOnFail: false,
95+
backoff: {
96+
type: 'exponential',
97+
delay: 1000,
98+
},
99+
},
100+
},
29101

102+
// SQS driver - AWS Simple Queue Service
30103
sqs: {
31104
driver: 'sqs',
32-
key: '', // set this if you
33-
secret: '',
34-
prefix: '',
35-
suffix: '',
105+
key: env.AWS_ACCESS_KEY_ID || '',
106+
secret: env.AWS_SECRET_ACCESS_KEY || '',
107+
prefix: env.SQS_PREFIX || '',
108+
suffix: env.SQS_SUFFIX || '',
36109
queue: 'default',
37-
region: 'us-east-1',
110+
region: env.AWS_REGION || 'us-east-1',
111+
},
112+
113+
// Memory driver - in-memory queue (for testing)
114+
memory: {
115+
driver: 'memory',
116+
maxSize: 10000,
38117
},
39118
},
119+
120+
// Failed jobs configuration
121+
failed: {
122+
driver: env.QUEUE_FAILED_DRIVER || 'database',
123+
table: 'failed_jobs',
124+
prefix: 'stacks:failed',
125+
},
126+
127+
// Batching configuration
128+
batching: {
129+
driver: 'redis',
130+
prefix: 'stacks:batches',
131+
},
132+
133+
// Worker configuration
134+
worker: {
135+
concurrency: env.QUEUE_WORKER_CONCURRENCY || 5,
136+
shutdownTimeout: 30000,
137+
},
40138
} satisfies QueueConfig

config/realtime.ts

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,103 @@ import { env } from '@stacksjs/env'
77
* This configuration defines all of your realtime options. Because Stacks is fully-typed,
88
* you may hover any of the options below and the definitions will be provided. In case
99
* you have any questions, feel free to reach out via Discord or GitHub Discussions.
10+
*
11+
* Stacks supports two deployment modes:
12+
* - 'server': Uses ts-broadcasting (high-performance Bun WebSocket server)
13+
* - 'serverless': Uses API Gateway WebSocket + Lambda + DynamoDB
1014
*/
1115
export default {
12-
driver: env.BROADCAST_DRIVER || 'socket',
16+
enabled: true,
17+
18+
// Deployment mode: 'server' (ts-broadcasting) or 'serverless' (API Gateway)
19+
mode: env.REALTIME_MODE || 'server',
20+
21+
// Legacy driver option (for backward compatibility)
22+
driver: env.BROADCAST_DRIVER || 'bun',
23+
24+
// Server mode configuration (ts-broadcasting)
25+
server: {
26+
host: env.BROADCAST_HOST || '0.0.0.0',
27+
port: env.BROADCAST_PORT || 6001,
28+
scheme: env.BROADCAST_SCHEME || 'ws',
29+
driver: 'bun',
30+
31+
// Redis adapter for horizontal scaling
32+
redis: {
33+
enabled: env.BROADCAST_REDIS_ENABLED || false,
34+
host: env.REDIS_HOST || 'localhost',
35+
port: env.REDIS_PORT || 6379,
36+
password: env.REDIS_PASSWORD,
37+
prefix: env.BROADCAST_REDIS_PREFIX || 'stacks:realtime:',
38+
},
39+
40+
// Rate limiting
41+
rateLimit: {
42+
enabled: env.BROADCAST_RATE_LIMIT_ENABLED || true,
43+
maxConnectionsPerIp: 100,
44+
maxMessagesPerSecond: 50,
45+
maxPayloadSize: 65536,
46+
banDuration: 300,
47+
},
48+
49+
// Load management
50+
loadManagement: {
51+
maxConnections: 10000,
52+
backpressureThreshold: 1000,
53+
messageQueueSize: 10000,
54+
gracefulShutdownTimeout: 30000,
55+
},
56+
57+
// Auto-scaling (for cloud deployment)
58+
autoScaling: {
59+
min: 1,
60+
max: 10,
61+
targetCPU: 70,
62+
},
1363

64+
// Health check endpoint
65+
healthCheck: {
66+
enabled: true,
67+
path: '/health',
68+
interval: 30,
69+
},
70+
71+
// Metrics endpoint
72+
metrics: {
73+
enabled: env.BROADCAST_METRICS_ENABLED || false,
74+
port: 9090,
75+
path: '/metrics',
76+
},
77+
},
78+
79+
// Serverless mode configuration (API Gateway WebSocket)
80+
serverless: {
81+
connectionTimeout: 3600,
82+
idleTimeout: 600,
83+
stageName: env.APP_ENV || 'production',
84+
memorySize: 256,
85+
timeout: 30,
86+
},
87+
88+
// Channel configuration
89+
channels: {
90+
public: true,
91+
private: true,
92+
presence: {
93+
enabled: true,
94+
maxMembersPerChannel: 100,
95+
memberInfoTtl: 60,
96+
},
97+
},
98+
99+
// Application credentials (for Pusher-compatible servers)
100+
app: {
101+
id: env.BROADCAST_APP_ID || 'stacks',
102+
key: env.BROADCAST_APP_KEY || '',
103+
secret: env.BROADCAST_APP_SECRET || '',
104+
},
105+
106+
// Legacy socket configuration
14107
socket: {
15108
port: env.BROADCAST_PORT || 6001,
16109
host: env.BROADCAST_HOST || 'localhost',
@@ -20,11 +113,15 @@ export default {
20113
},
21114
},
22115

116+
// Legacy Pusher configuration
23117
pusher: {
24118
appId: env.PUSHER_APP_ID || '',
25119
key: env.PUSHER_APP_KEY || '',
26120
secret: env.PUSHER_APP_SECRET || '',
27121
cluster: env.PUSHER_APP_CLUSTER || 'mt1',
28122
useTLS: env.PUSHER_APP_USE_TLS || true,
29123
},
124+
125+
// Debug mode
126+
debug: env.BROADCAST_DEBUG || false,
30127
} satisfies RealtimeConfig

storage/framework/core/actions/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ export {
3030
makeStack,
3131
make as runMake,
3232
} from './make'
33+
34+
export { makeJob } from './make-job'

0 commit comments

Comments
 (0)