Skip to content

Commit

Permalink
fix(convert): store failed step in convert start (#716)
Browse files Browse the repository at this point in the history
* Revert "chore(deps): bump fastify from 4.1.0 to 4.8.1 (#689)"

This reverts commit 6c4b648.

* upgrade fast-jwt

* fix(convert): store failed step in convert start

* refactor: support opt-out transaction in dao
  • Loading branch information
hyrious authored Feb 7, 2023
1 parent faff419 commit 49acdb8
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 148 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@fastify/cookie": "^8.3.0",
"@fastify/cors": "^8.0.0",
"@fastify/formbody": "^7.0.1",
"@fastify/jwt": "^6.1.0",
"@fastify/jwt": "^6.5.0",
"@fastify/type-provider-typebox": "^1.0.0",
"@fastify/view": "^7.1.0",
"@sinclair/typebox": "^0.23.5",
Expand All @@ -78,8 +78,8 @@
"crypto-random-string": "^3.3.0",
"date-fns": "^2.16.1",
"eta": "^1.12.3",
"fast-jwt": "^1.6.0",
"fastify": "^4.8.1",
"fast-jwt": "^2.1.0",
"fastify": "^4.1.0",
"fastify-plugin": "^3.0.1",
"filenamify": "^4.3.0",
"fs-extra": "^10.0.0",
Expand Down
6 changes: 3 additions & 3 deletions src/v2/dao/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { CloudStorageConfigsModel } from "../../model/cloudStorage/CloudStorageC
import { OAuthInfosModel } from "../../model/oauth/oauth-infos";
import { OAuthSecretsModel } from "../../model/oauth/oauth-secrets";
import { OAuthUsersModel } from "../../model/oauth/oauth-users";
import { dataSource } from "../../thirdPartyService/TypeORMService";

class DAO<M extends Model> {
public constructor(private readonly model: EntityTarget<M>) {}
Expand Down Expand Up @@ -117,16 +118,15 @@ class DAO<M extends Model> {
}

public async update(
t: EntityManager,
t: EntityManager | null,
updateData: QueryDeepPartialEntity<M>,
where: FindOptionsWhere<M>,
config?: {
order?: [keyof M & string, "ASC" | "DESC"];
limit?: number;
},
): Promise<void> {
let sql = t
.createQueryBuilder()
let sql = (t ? t.createQueryBuilder() : dataSource.createQueryBuilder())
.update(this.model)
.set(updateData)
.where(DAOUtils.softDelete(where))
Expand Down
35 changes: 35 additions & 0 deletions src/v2/services/cloud-storage/__tests__/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,41 @@ test(`${namespace} - start whiteboard projector - convertStep not none`, async a
await releaseRunner();
});

test.serial(`${namespace} - start whiteboard projector - failed`, async ava => {
const stubAxios = sinon.stub(ax, "post").resolves({
data: {
uuid: undefined,
},
});

const { t, releaseRunner } = await useTransaction();

const fileUUID = v4();

const cloudStorageConvertSVC = new CloudStorageConvertService(ids(), t, fileUUID);

await ava.throwsAsync(
() =>
cloudStorageConvertSVC.startWhiteboardProjector(v4(), v4(), {
region: Region.SG,
convertStep: FileConvertStep.Converting,
}),
{
instanceOf: FError,
message: `${Status.Failed}: ${ErrorCode.FileConvertFailed}`,
},
);

const data = await cloudStorageFilesDAO.findOne(t, 'payload', {
file_uuid: fileUUID,
});

ava.is((data.payload as any)?.convertStep, FileConvertStep.Failed);

stubAxios.restore();
await releaseRunner();
});

test.serial(`${namespace} - start whiteboard projector - success`, async ava => {
const { t, releaseRunner } = await useTransaction();
const { createCloudStorageFiles } = testService(t);
Expand Down
36 changes: 36 additions & 0 deletions src/v2/services/cloud-storage/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ export class CloudStorageConvertService {
const whiteboardConversionSVC = new WhiteboardConversionService(this.ids);

const taskUUID = await whiteboardConversionSVC.create(fileURL);
if (!taskUUID) {
await cloudStorageFilesDAO.update(
// we don't want to rollback this action
null,
{
payload: {
convertStep: FileConvertStep.Failed,
region: payload.region,
},
},
{
file_uuid: fileUUID,
}
)

throw new FError(ErrorCode.FileConvertFailed);
}

const taskToken = WhiteboardTokenService.createTask(taskUUID);

await cloudStorageFilesDAO.update(
Expand Down Expand Up @@ -193,6 +211,24 @@ export class CloudStorageConvertService {
const whiteboardProjectorSVC = new WhiteboardProjectorService(this.ids);

const taskUUID = await whiteboardProjectorSVC.create(fileURL);
if (!taskUUID) {
await cloudStorageFilesDAO.update(
// we don't want to rollback this action
null,
{
payload: {
convertStep: FileConvertStep.Failed,
region: payload.region,
},
},
{
file_uuid: fileUUID,
}
)

throw new FError(ErrorCode.FileConvertFailed);
}

const taskToken = WhiteboardTokenService.createTask(taskUUID);

await cloudStorageFilesDAO.update(
Expand Down
2 changes: 1 addition & 1 deletion src/v2/services/whiteboard/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class WhiteboardConversionService {

public constructor(private readonly ids: IDS) {}

public async create(resource: string): Promise<string> {
public async create(resource: string): Promise<string | undefined> {
const result = await ax.post<TaskCreated>(
"https://api.netless.link/v5/services/conversion/tasks",
{
Expand Down
2 changes: 1 addition & 1 deletion src/v2/services/whiteboard/projector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class WhiteboardProjectorService {

public constructor(private readonly ids: IDS) {}

public async create(resource: string): Promise<string> {
public async create(resource: string): Promise<string | undefined> {
const { data } = await ax.post<TaskCreated>(
"https://api.netless.link/v5/projector/tasks",
{
Expand Down
Loading

0 comments on commit 49acdb8

Please sign in to comment.