Skip to content

Commit

Permalink
Fix migration tool not running queue for previews
Browse files Browse the repository at this point in the history
  • Loading branch information
RomaricMourgues committed Mar 24, 2023
1 parent 9c50ebf commit d44c166
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions twake/backend/node/src/cli/cmds/migration_cmds/drive.ts
Expand Up @@ -18,6 +18,7 @@ const services = [
"tracker",
"websocket",
"email-pusher",
"files",
];

const command: yargs.CommandModule<unknown, unknown> = {
Expand Down
Expand Up @@ -80,7 +80,13 @@ class DriveMigrator {
logger.info(`Migrating company ${company.id}`);

const companyAdminOrOwnerId = await this.getCompanyOwnerOrAdminId(company.id, context);
if (!companyAdminOrOwnerId) {
return;
}
const workspaceList = await globalResolver.services.workspaces.getAllForCompany(company.id);
if (!workspaceList || workspaceList.length === 0) {
return;
}

for (const workspace of workspaceList) {
const wsContext = {
Expand Down Expand Up @@ -252,6 +258,9 @@ class DriveMigrator {
context,
);

logger.info(
`Migrating version ${version.id} of item ${item.id}... (downloading then uploading...)`,
);
const file = await this.phpDriveService.migrate(
version.file_id,
item.workspace_id,
Expand Down Expand Up @@ -331,6 +340,9 @@ class DriveMigrator {
{ pagination },
context,
);
if (!companyUsers.getEntities().length && !pagination?.page_token) {
return null;
}

pagination = companyUsers.nextPage as Pagination;

Expand All @@ -341,7 +353,7 @@ class DriveMigrator {
if (companyAdminOrOwner) {
companyOwnerOrAdminId = companyAdminOrOwner.id;
}
} while (pagination && !companyOwnerOrAdminId);
} while (pagination?.page_token && !companyOwnerOrAdminId);

return companyOwnerOrAdminId;
};
Expand Down
Expand Up @@ -12,7 +12,7 @@ export const TYPE = "drive_file";
})
export class PhpDriveFile {
@Type(() => String)
@Column("workspace_id", "timeuuid")
@Column("workspace_id", "string")
workspace_id: string;

@Type(() => String)
Expand Down
Expand Up @@ -16,7 +16,7 @@ export class PhpDriveFileVersion {
id: string;

@Type(() => String)
@Column("file_id", "string")
@Column("file_id", "timeuuid")
file_id: string;

@Type(() => String)
Expand Down
Expand Up @@ -9,7 +9,6 @@ import {
} from "../api";
import MessageQueueProxy from "../proxy";
import { AMQPMessageQueueManager } from "./manager";
import { SkipCLI } from "../../../framework/decorators/skip";

const logger = rootLogger.child({
component: "twake.core.platform.services.message-queue.amqp",
Expand All @@ -28,7 +27,6 @@ export class AMQPMessageQueueService implements MessageQueueAdapter {
this.clientProxy = new MessageQueueProxy();
}

@SkipCLI()
async init(): Promise<this> {
logger.info("Initializing message-queue service implementation with urls %o", this.urls);
await this.manager.createClient(this.urls);
Expand Down
Expand Up @@ -17,7 +17,7 @@ export class MessageQueueAdapterFactory {
logger.info("Building Adapter %o", type);

switch (type) {
case "local":
case "local" || process.env.NODE_ENV === "cli":
return new LocalMessageQueueService();
case "amqp":
let urls: string[] = configuration.get<string[]>("amqp.urls", [DEFAULT_AMQP_URL]);
Expand Down
Expand Up @@ -9,7 +9,6 @@ import {
import { eventBus } from "./bus";
import { Processor } from "./processor";
import adapterFactory from "./factory";
import { SkipCLI } from "../../framework/decorators/skip";
import config from "../../../../core/config";

const logger = rootLogger.child({
Expand Down Expand Up @@ -61,15 +60,13 @@ export class MessageQueueService implements MessageQueueServiceAPI {
this.processor = new Processor(this);
}

@SkipCLI()
async init(): Promise<this> {
logger.info("Initializing message-queue adapter %o", this.adapter.type);
await this.adapter?.init?.();

return this;
}

@SkipCLI()
async start(): Promise<this> {
logger.info("Starting message-queue adapter %o", this.adapter.type);
await this.adapter?.start?.();
Expand All @@ -78,7 +75,6 @@ export class MessageQueueService implements MessageQueueServiceAPI {
return this;
}

@SkipCLI()
async stop(): Promise<this> {
logger.info("Stopping message-queue adapter %o", this.adapter.type);
await this.adapter?.stop?.();
Expand Down
4 changes: 2 additions & 2 deletions twake/backend/node/src/services/files/services/preview.ts
Expand Up @@ -30,7 +30,7 @@ export class PreviewFinishedProcessor
name = "FilePreviewProcessor";

validate(message: PreviewMessageQueueCallback): boolean {
return !!(message && message.document && message.thumbnails);
return !!(message && message.document);
}

async process(message: PreviewMessageQueueCallback, context?: ExecutionContext): Promise<string> {
Expand All @@ -46,7 +46,7 @@ export class PreviewFinishedProcessor
return;
}

entity.thumbnails = message.thumbnails.map((thumb, index) => {
entity.thumbnails = (message.thumbnails || []).map((thumb, index) => {
return {
index,
id: thumb.path.split("/").pop(),
Expand Down

0 comments on commit d44c166

Please sign in to comment.