Skip to content

Commit

Permalink
fix: retry modules init (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinganix authored Jan 29, 2024
1 parent e398b90 commit f194dec
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
29 changes: 18 additions & 11 deletions frontend/weapp/src/helpers/module/module.initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,29 @@ export async function tryInitializeModules(): Promise<boolean> {
export class AppInitializer {
disposes: Dispose[] = [];

async tryInitializeModules(attempts: number): Promise<void> {
if (!attempts) {
return;
}
try {
this.disposes = await initializeModules();
} catch (err) {
if (err === ErrorCode.FORCE_LOGOUT) {
await deleteAuthToken();
await this.tryInitializeModules(attempts - 1);
} else {
console.error("initialize failed", err);
}
}
}

initialize(options: LaunchShowOption): void {
const scene = (options as { scene: number }).scene;
const preview = scene === 1154 || scene === 1155;
configStore.updatePreview(preview);
if (preview) {
return;
if (!preview) {
void this.tryInitializeModules(2);
}
initializeModules()
.then((disposes) => (this.disposes = disposes))
.catch((err) => {
if (err === ErrorCode.FORCE_LOGOUT) {
void deleteAuthToken();
} else {
console.error("initialize failed", err);
}
});
}

onAppDispose(): Dispose {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public String getAccessToken() {
return orderedTraceExecutor.supply(
"ACCESS_TOKEN",
() -> {
if (accessToken != null && createdAt + TimeUnit.MINUTES.toMillis(30) > millis) {
return this.accessToken;
}
WeappAccessTokenRequest request = new WeappAccessTokenRequest(appId, appSecret);
WeappAccessTokenResponse response =
weappClient.request(request, WeappAccessTokenResponse.class);
Expand Down
1 change: 1 addition & 0 deletions service/guess/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ core:
config:
puzzle-daily-limit: 30
puzzle-limit-increase: 20
static-url: http://127.0.0.1:8080/static/
jwt-secret: test-jwt-secret
url:
db-mysql: jdbc:mysql://127.0.0.1:3306/guess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MysqlContainer extends MySQLContainer<MysqlContainer> {
/** Constructor. */
public MysqlContainer() {
super(
DockerImageName.parse(isArm64() ? "arm64v8/mysql:8.2.0" : "mysql:8.2.0")
DockerImageName.parse(isArm64() ? "arm64v8/mysql:8.3.0" : "mysql:8.3.0")
.asCompatibleSubstituteFor("mysql"));
}

Expand Down

0 comments on commit f194dec

Please sign in to comment.