|
| 1 | +import { feathers } from '@feathersjs/feathers' |
| 2 | +import express from '@feathersjs/express' |
| 3 | +import socketio from '@feathersjs/socketio' |
| 4 | +import { MemoryService } from '@feathersjs/memory' |
| 5 | +import { TaskService, createQueue, setupQueueEvents, setupDashboard } from '@kalisio/feathers-tasks' |
| 6 | + |
| 7 | +const port = Number(process.env.SERVER_PORT) || 3030 |
| 8 | +const redis = { |
| 9 | + host: process.env.REDIS_HOST || 'localhost', |
| 10 | + port: Number(process.env.REDIS_PORT) || 6379 |
| 11 | +} |
| 12 | +const queueName = process.env.QUEUE_NAME || 'orchestration-tasks' |
| 13 | + |
| 14 | +const app = express(feathers()) |
| 15 | + |
| 16 | +app.use(express.json()) |
| 17 | +app.use(express.urlencoded({ extended: true })) |
| 18 | +app.configure(express.rest()) |
| 19 | +app.configure(socketio({ cors: { origin: '*' } })) |
| 20 | + |
| 21 | +app.use('task-store', new MemoryService()) |
| 22 | + |
| 23 | +const queue = createQueue(queueName, redis) |
| 24 | + |
| 25 | +setupQueueEvents(queueName, redis, app, 'task-store') |
| 26 | + |
| 27 | +setupDashboard(app, queue, '/admin/tasks') |
| 28 | + |
| 29 | +app.use('tasks', new TaskService({ queue, persistenceService: 'task-store' })) |
| 30 | + |
| 31 | +app.on('connection', connection => app.channel('anonymous').join(connection)) |
| 32 | +app.publish(() => app.channel('anonymous')) |
| 33 | + |
| 34 | +await app.setup() |
| 35 | + |
| 36 | +app.listen(port).then(() => { |
| 37 | + console.log(`Server listening on http://localhost:${port}`) |
| 38 | + console.log(`Bull Board: http://localhost:${port}/admin/tasks`) |
| 39 | + console.log(`Redis: ${redis.host}:${redis.port}`) |
| 40 | + console.log(`Queue: ${queueName}`) |
| 41 | + console.log() |
| 42 | + console.log('Submit a swarm job:') |
| 43 | + console.log(` curl -X POST http://localhost:${port}/tasks -H 'Content-Type: application/json' \\`) |
| 44 | + console.log(' -d \'{"type":"swarm-job","payload":{"label":"hello from swarm","steps":4}}\'') |
| 45 | + console.log() |
| 46 | + console.log('Submit a k8s job:') |
| 47 | + console.log(` curl -X POST http://localhost:${port}/tasks -H 'Content-Type: application/json' \\`) |
| 48 | + console.log(' -d \'{"type":"k8s-job","payload":{"label":"hello from k8s","steps":3}}\'') |
| 49 | +}) |
0 commit comments