fix: 修复不稳定的更新状态和错误的 preset (#985)

Reviewed-on: daoyoucloud/tachybase#985
This commit is contained in:
sealday 2024-05-15 13:12:55 +08:00
parent b46c9ee827
commit f08c5b6332
18 changed files with 38 additions and 18 deletions

View File

@ -52,6 +52,7 @@
"@tachybase/build": "workspace:*", "@tachybase/build": "workspace:*",
"@tachybase/cli": "workspace:*", "@tachybase/cli": "workspace:*",
"@tachybase/preset-hera-rental": "workspace:*", "@tachybase/preset-hera-rental": "workspace:*",
"@tachybase/preset-hera-sancongtou": "workspace:*",
"@tachybase/preset-tachybase": "workspace:*", "@tachybase/preset-tachybase": "workspace:*",
"@tachybase/test": "workspace:*", "@tachybase/test": "workspace:*",
"@types/react": "^18.2.79", "@types/react": "^18.2.79",

View File

@ -8,7 +8,7 @@
"dependencies": { "dependencies": {
"@tachybase/database": "workspace:*", "@tachybase/database": "workspace:*",
"@tachybase/preset-hera-rental": "workspace:*", "@tachybase/preset-hera-rental": "workspace:*",
"@tachybase/preset-sancongtou": "workspace:*", "@tachybase/preset-hera-sancongtou": "workspace:*",
"@tachybase/preset-tachybase": "workspace:*", "@tachybase/preset-tachybase": "workspace:*",
"@tachybase/server": "workspace:*" "@tachybase/server": "workspace:*"
}, },

View File

@ -1,5 +1,5 @@
import { CleanOptions, Collection, SyncOptions } from '@tachybase/database'; import { CleanOptions, Collection, SyncOptions } from '@tachybase/database';
import { importModule, isURL } from '@tachybase/utils'; import { Container, importModule, isURL } from '@tachybase/utils';
import { fsExists } from '@tachybase/utils/plugin-symlink'; import { fsExists } from '@tachybase/utils/plugin-symlink';
import execa from 'execa'; import execa from 'execa';
import fg from 'fast-glob'; import fg from 'fast-glob';
@ -381,6 +381,10 @@ export class PluginManager {
} }
async load(options: any = {}) { async load(options: any = {}) {
// FIXME
Container.reset();
Container.set({ id: 'db', value: this.app.db });
Container.set({ id: 'app', value: this.app });
this.app.setMaintainingMessage('loading plugins...'); this.app.setMaintainingMessage('loading plugins...');
const total = this.pluginInstances.size; const total = this.pluginInstances.size;

View File

@ -32,16 +32,12 @@ export class PluginCoreServer extends Plugin {
async load() { async load() {
await this.pluginDepartments.load(); await this.pluginDepartments.load();
await this.pluginInterception.load(); await this.pluginInterception.load();
Container.reset();
try { try {
Container.set({ id: 'db', value: this.db });
Container.set({ id: 'app', value: this.app });
await Container.get(ConnectionManager).load(); await Container.get(ConnectionManager).load();
const fontManger = Container.get(FontManager); const fontManger = Container.get(FontManager);
const sqlLoader = Container.get(SqlLoader); const sqlLoader = Container.get(SqlLoader);
await sqlLoader.loadSqlFiles(path.join(__dirname, './sqls')); await sqlLoader.loadSqlFiles(path.join(__dirname, './sqls'));
await fontManger.loadFonts(); await fontManger.loadFonts();
await Container.get(HomePageService).load();
// init web controllers // init web controllers
await Container.get(WebService).load(); await Container.get(WebService).load();
this.app.acl.allow('link-manage', 'init', 'public'); this.app.acl.allow('link-manage', 'init', 'public');
@ -52,6 +48,7 @@ export class PluginCoreServer extends Plugin {
} }
async install(options?: InstallOptions) { async install(options?: InstallOptions) {
await this.pluginDepartments.install(options); await this.pluginDepartments.install(options);
await Container.get(HomePageService).install();
} }
async afterEnable() {} async afterEnable() {}
async afterDisable() {} async afterDisable() {}

View File

@ -20,7 +20,7 @@ export class ConnectionManager {
async unload() { async unload() {
for (const client of [this.redisClient, this.redisPubClient, this.redisSubClient]) { for (const client of [this.redisClient, this.redisPubClient, this.redisSubClient]) {
if (client.isOpen) { if (client.isOpen) {
await this.redisClient.disconnect(); await client.disconnect();
} }
} }
} }
@ -32,6 +32,9 @@ export class ConnectionManager {
await this.redisClient.connect(); await this.redisClient.connect();
await this.redisPubClient.connect(); await this.redisPubClient.connect();
await this.redisSubClient.connect(); await this.redisSubClient.connect();
this.app.on('afterStop', () => {
this.unload();
});
if (isMain()) { if (isMain()) {
const keysToDelete: any = await this.redisClient.KEYS(`${KEY_ONLINE_USERS}*`); const keysToDelete: any = await this.redisClient.KEYS(`${KEY_ONLINE_USERS}*`);
if (keysToDelete.length > 0) { if (keysToDelete.length > 0) {

View File

@ -10,7 +10,7 @@ export class HomePageService {
@Db() @Db()
private db: Database; private db: Database;
async load() { async install() {
this.app.acl.allow('home_page_presentations', 'list', 'public'); this.app.acl.allow('home_page_presentations', 'list', 'public');
const repo = this.db.getRepository<any>('collections'); const repo = this.db.getRepository<any>('collections');
if (repo) { if (repo) {

View File

@ -2,11 +2,17 @@ import PresetTachyBase from '@tachybase/preset-tachybase';
import _ from 'lodash'; import _ from 'lodash';
export class PluginRental extends PresetTachyBase { export class PluginRental extends PresetTachyBase {
#builtInPlugins = ['approval-mobile', 'core', 'rental', 'mobile-client']; #builtInPlugins = ['approval-mobile', 'core'];
get builtInPlugins() { get builtInPlugins() {
return super.builtInPlugins.concat(this.#builtInPlugins); return super.builtInPlugins.concat(this.#builtInPlugins);
} }
#localPlugins = ['rental>=0.21.0'];
get localPlugins() {
return super.localPlugins.concat(this.#localPlugins);
}
} }
export default PresetTachyBase; export default PluginRental;

View File

@ -1,5 +1,5 @@
{ {
"name": "@tachybase/preset-sancongtou", "name": "@tachybase/preset-hera-sancongtou",
"version": "0.21.20", "version": "0.21.20",
"license": "Apache-2.0", "license": "Apache-2.0",
"main": "./lib/server/index.js", "main": "./lib/server/index.js",

View File

@ -1,12 +1,18 @@
import PresetTachyBase from '@tachybase/preset-tachybase'; import PresetTachyBase from '@tachybase/preset-tachybase';
import _ from 'lodash'; import _ from 'lodash';
export class PluginRental extends PresetTachyBase { export class PluginSancongtou extends PresetTachyBase {
#builtInPlugins = ['approval-mobile', 'core', 'rental', 'mobile-client', 'sancongtou']; #builtInPlugins = ['approval-mobile', 'core'];
get builtInPlugins() { get builtInPlugins() {
return super.builtInPlugins.concat(this.#builtInPlugins); return super.builtInPlugins.concat(this.#builtInPlugins);
} }
#localPlugins = ['sancongtou>=0.21.0'];
get localPlugins() {
return super.localPlugins.concat(this.#localPlugins);
}
} }
export default PresetTachyBase; export default PluginSancongtou;

View File

@ -51,7 +51,10 @@ importers:
version: link:packages/core/cli version: link:packages/core/cli
'@tachybase/preset-hera-rental': '@tachybase/preset-hera-rental':
specifier: workspace:* specifier: workspace:*
version: link:packages/presets/hera-rental version: link:packages/presets/rental
'@tachybase/preset-hera-sancongtou':
specifier: workspace:*
version: link:packages/presets/sancongtou
'@tachybase/preset-tachybase': '@tachybase/preset-tachybase':
specifier: workspace:* specifier: workspace:*
version: link:packages/presets/base version: link:packages/presets/base
@ -169,8 +172,8 @@ importers:
version: link:../database version: link:../database
'@tachybase/preset-hera-rental': '@tachybase/preset-hera-rental':
specifier: workspace:* specifier: workspace:*
version: link:../../presets/hera-rental version: link:../../presets/rental
'@tachybase/preset-sancongtou': '@tachybase/preset-hera-sancongtou':
specifier: workspace:* specifier: workspace:*
version: link:../../presets/sancongtou version: link:../../presets/sancongtou
'@tachybase/preset-tachybase': '@tachybase/preset-tachybase':
@ -4174,7 +4177,7 @@ importers:
specifier: ^4.17.0 specifier: ^4.17.0
version: 4.17.0 version: 4.17.0
packages/presets/hera-rental: packages/presets/rental:
dependencies: dependencies:
'@hera/plugin-approval': '@hera/plugin-approval':
specifier: workspace:* specifier: workspace:*