feat: plugin-bullmq-adapter (#1365)
Co-authored-by: sealday <sealday@gmail.com> Reviewed-on: daoyoucloud/tachybase#1365
This commit is contained in:
		
							parent
							
								
									7756c18cb1
								
							
						
					
					
						commit
						9ffd94155a
					
				| @ -14,6 +14,7 @@ APP_ENV=development | |||||||
| APP_PORT=13000 | APP_PORT=13000 | ||||||
| APP_KEY=test-key | APP_KEY=test-key | ||||||
| 
 | 
 | ||||||
|  | EXTENSION_UI_BASE_PATH=/adapters/ | ||||||
| API_BASE_PATH=/api/ | API_BASE_PATH=/api/ | ||||||
| API_BASE_URL= | API_BASE_URL= | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -66,6 +66,19 @@ server { | |||||||
|         send_timeout 600; |         send_timeout 600; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     location ^~ /adapters/ { | ||||||
|  |         proxy_pass http://127.0.0.1:13000/adapters/; | ||||||
|  |         proxy_http_version 1.1; | ||||||
|  |         proxy_set_header Upgrade $http_upgrade; | ||||||
|  |         proxy_set_header Connection 'upgrade'; | ||||||
|  |         proxy_set_header Host $host; | ||||||
|  |         proxy_cache_bypass $http_upgrade; | ||||||
|  |         proxy_connect_timeout 600; | ||||||
|  |         proxy_send_timeout 600; | ||||||
|  |         proxy_read_timeout 600; | ||||||
|  |         send_timeout 600; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     location ^~ /static/plugins/ { |     location ^~ /static/plugins/ { | ||||||
|         proxy_pass http://127.0.0.1:13000/static/plugins/; |         proxy_pass http://127.0.0.1:13000/static/plugins/; | ||||||
|         proxy_http_version 1.1; |         proxy_http_version 1.1; | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ console.log('VERSION: ', packageJson.version); | |||||||
| function getUmiConfig() { | function getUmiConfig() { | ||||||
|   const { APP_PORT, API_BASE_URL, APP_PUBLIC_PATH } = process.env; |   const { APP_PORT, API_BASE_URL, APP_PUBLIC_PATH } = process.env; | ||||||
|   const API_BASE_PATH = process.env.API_BASE_PATH || '/api/'; |   const API_BASE_PATH = process.env.API_BASE_PATH || '/api/'; | ||||||
|  |   const EXTENSION_UI_BASE_PATH = process.env.EXTENSION_UI_BASE_PATH || '/adapters/'; | ||||||
|   const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${APP_PORT}`; |   const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${APP_PORT}`; | ||||||
|   const LOCAL_STORAGE_BASE_URL = 'storage/uploads/'; |   const LOCAL_STORAGE_BASE_URL = 'storage/uploads/'; | ||||||
|   const STATIC_PATH = 'static/'; |   const STATIC_PATH = 'static/'; | ||||||
| @ -53,6 +54,11 @@ function getUmiConfig() { | |||||||
|         changeOrigin: true, |         changeOrigin: true, | ||||||
|         pathRewrite: { [`^${API_BASE_PATH}`]: API_BASE_PATH }, |         pathRewrite: { [`^${API_BASE_PATH}`]: API_BASE_PATH }, | ||||||
|       }, |       }, | ||||||
|  |       [EXTENSION_UI_BASE_PATH]: { | ||||||
|  |         target: PROXY_TARGET_URL, | ||||||
|  |         changeOrigin: true, | ||||||
|  |         pathRewrite: { [`^${EXTENSION_UI_BASE_PATH}`]: EXTENSION_UI_BASE_PATH }, | ||||||
|  |       }, | ||||||
|       // for local storage
 |       // for local storage
 | ||||||
|       ...getLocalStorageProxy(), |       ...getLocalStorageProxy(), | ||||||
|     }, |     }, | ||||||
|  | |||||||
| @ -207,7 +207,7 @@ export class Gateway extends EventEmitter { | |||||||
|       }); |       }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (!pathname.startsWith(process.env.API_BASE_PATH)) { |     if (!pathname.startsWith(process.env.API_BASE_PATH) && !pathname.startsWith(process.env.EXTENSION_UI_BASE_PATH)) { | ||||||
|       req.url = req.url.substring(APP_PUBLIC_PATH.length - 1); |       req.url = req.url.substring(APP_PUBLIC_PATH.length - 1); | ||||||
|       await compress(req, res); |       await compress(req, res); | ||||||
|       return handler(req, res, { |       return handler(req, res, { | ||||||
|  | |||||||
| @ -0,0 +1,2 @@ | |||||||
|  | /node_modules | ||||||
|  | /src | ||||||
| @ -0,0 +1 @@ | |||||||
|  | # @tachybase/plugin-adapter-bullmq | ||||||
							
								
								
									
										2
									
								
								packages/plugins/@tachybase/plugin-adapter-bullmq/client.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								packages/plugins/@tachybase/plugin-adapter-bullmq/client.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | export * from './dist/client'; | ||||||
|  | export { default } from './dist/client'; | ||||||
| @ -0,0 +1 @@ | |||||||
|  | module.exports = require('./dist/client/index.js'); | ||||||
| @ -0,0 +1,15 @@ | |||||||
|  | { | ||||||
|  |   "name": "@tachybase/plugin-adapter-bullmq", | ||||||
|  |   "version": "0.21.75", | ||||||
|  |   "main": "dist/server/index.js", | ||||||
|  |   "devDependencies": { | ||||||
|  |     "@bull-board/api": "^5.21.1", | ||||||
|  |     "@bull-board/koa": "^5.21.1", | ||||||
|  |     "bullmq": "^5.10.1" | ||||||
|  |   }, | ||||||
|  |   "peerDependencies": { | ||||||
|  |     "@tachybase/client": "workspace:*", | ||||||
|  |     "@tachybase/server": "workspace:*", | ||||||
|  |     "@tachybase/test": "workspace:*" | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										2
									
								
								packages/plugins/@tachybase/plugin-adapter-bullmq/server.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								packages/plugins/@tachybase/plugin-adapter-bullmq/server.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | export * from './dist/server'; | ||||||
|  | export { default } from './dist/server'; | ||||||
| @ -0,0 +1 @@ | |||||||
|  | module.exports = require('./dist/server/index.js'); | ||||||
| @ -0,0 +1,5 @@ | |||||||
|  | import { Plugin } from '@tachybase/client'; | ||||||
|  | 
 | ||||||
|  | export class PluginAdapterBullmqClient extends Plugin {} | ||||||
|  | 
 | ||||||
|  | export default PluginAdapterBullmqClient; | ||||||
| @ -0,0 +1,2 @@ | |||||||
|  | export * from './server'; | ||||||
|  | export { default } from './server'; | ||||||
| @ -0,0 +1 @@ | |||||||
|  | export { default } from './plugin'; | ||||||
| @ -0,0 +1,40 @@ | |||||||
|  | import { Plugin } from '@tachybase/server'; | ||||||
|  | 
 | ||||||
|  | import { createBullBoard } from '@bull-board/api'; | ||||||
|  | import { BullMQAdapter } from '@bull-board/api/bullMQAdapter'; | ||||||
|  | import { KoaAdapter } from '@bull-board/koa'; | ||||||
|  | import { Queue } from 'bullmq'; | ||||||
|  | 
 | ||||||
|  | export class PluginAdapterBullmqServer extends Plugin { | ||||||
|  |   async afterAdd() {} | ||||||
|  | 
 | ||||||
|  |   async beforeLoad() {} | ||||||
|  | 
 | ||||||
|  |   async load() { | ||||||
|  |     const redisOptions = { | ||||||
|  |       port: Number(process.env.REDIS_PORT || 6379), | ||||||
|  |       host: process.env.REDIS_HOST || 'localhost', | ||||||
|  |       password: process.env.REDIS_PASSWORD || '', | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     const defaultQueue = new Queue(process.env.MSG_QUEUE_NAME || 'default', { connection: redisOptions }); | ||||||
|  | 
 | ||||||
|  |     const serverAdapter = new KoaAdapter(); | ||||||
|  |     createBullBoard({ | ||||||
|  |       queues: [new BullMQAdapter(defaultQueue)], | ||||||
|  |       serverAdapter, | ||||||
|  |     }); | ||||||
|  |     serverAdapter.setBasePath(process.env.EXTENSION_UI_BASE_PATH + 'mqui'); | ||||||
|  |     this.app.use(serverAdapter.registerPlugin(), { before: 'bodyParser' }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   async install() {} | ||||||
|  | 
 | ||||||
|  |   async afterEnable() {} | ||||||
|  | 
 | ||||||
|  |   async afterDisable() {} | ||||||
|  | 
 | ||||||
|  |   async remove() {} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export default PluginAdapterBullmqServer; | ||||||
| @ -150,6 +150,9 @@ export default class ApprovalTrigger extends Trigger { | |||||||
|     await approvalExecution.update({ status: execution.status }, { transaction }); |     await approvalExecution.update({ status: execution.status }, { transaction }); | ||||||
|   }; |   }; | ||||||
|   middleware = async (context, next) => { |   middleware = async (context, next) => { | ||||||
|  |     if (!context.action) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|     const { |     const { | ||||||
|       resourceName, |       resourceName, | ||||||
|       actionName, |       actionName, | ||||||
|  | |||||||
							
								
								
									
										894
									
								
								pnpm-lock.yaml
									
									
									
									
									
								
							
							
						
						
									
										894
									
								
								pnpm-lock.yaml
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user