Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] adjust migration job #17730

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/server/src/jobs/org-only-migration-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export class OrgOnlyMigrationJob implements Job {

const result: User[] = [];
for (const user of users) {
result.push(await this.migrationService.migrateUser(user));
result.push(await this.migrationService.migrateUser(user, true, this.name));
Copy link
Member

@geropl geropl May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the 2nd argument was false, right? Is that intended?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but it should be true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awh, makes sense. 💡

}
log.info("org-only-migration-job: migrated users", { count: result.length });
return result;
} catch (err) {
log.error("org-only-migration-job: error during run", err);
Expand All @@ -43,6 +44,6 @@ export class OrgOnlyMigrationJob implements Job {
}

public async run(): Promise<void> {
await this.migrateUsers(100);
await this.migrateUsers(1500); // in prod we do ~300 / minute
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class UserToTeamMigrationService {
@inject(RedisMutex) protected readonly redisMutex: RedisMutex;
@inject(StripeService) protected readonly stripeService: StripeService;

async migrateUser(candidate: User, shouldSeeMessage?: boolean): Promise<User> {
async migrateUser(candidate: User, shouldSeeMessage?: boolean, caller?: string): Promise<User> {
// do a quick check before going into synchonization for the common case that the user has been migrated already
if (!this.needsMigration(candidate)) {
return candidate;
Expand All @@ -51,6 +51,7 @@ export class UserToTeamMigrationService {
}
log.info({ userId: candidate.id }, "Migrated user to org.", {
timeMs: new Date().getTime() - now.getTime(),
caller,
});
return candidate;
});
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/user/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class UserService {
AdditionalUserData.set(newUser, { isMigratedToTeamOnlyAttribution: true });
newUser = await this.userDb.storeUser(newUser);
} else {
newUser = await this.migrationService.migrateUser(newUser, false);
newUser = await this.migrationService.migrateUser(newUser, false, "new user");
}

return newUser;
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {

if (this.user) {
if (this.userToTeamMigrationService.needsMigration(this.user)) {
this.user = await this.userToTeamMigrationService.migrateUser(this.user, true);
this.user = await this.userToTeamMigrationService.migrateUser(this.user, true, "on demand");
}
let updatedUser = await this.userDB.findUserById(this.user.id);
if (updatedUser) {
Expand Down