Skip to content

Commit 49acdb8

Browse files
authored
fix(convert): store failed step in convert start (#716)
* 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
1 parent faff419 commit 49acdb8

File tree

7 files changed

+194
-148
lines changed

7 files changed

+194
-148
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"@fastify/cookie": "^8.3.0",
6666
"@fastify/cors": "^8.0.0",
6767
"@fastify/formbody": "^7.0.1",
68-
"@fastify/jwt": "^6.1.0",
68+
"@fastify/jwt": "^6.5.0",
6969
"@fastify/type-provider-typebox": "^1.0.0",
7070
"@fastify/view": "^7.1.0",
7171
"@sinclair/typebox": "^0.23.5",
@@ -78,8 +78,8 @@
7878
"crypto-random-string": "^3.3.0",
7979
"date-fns": "^2.16.1",
8080
"eta": "^1.12.3",
81-
"fast-jwt": "^1.6.0",
82-
"fastify": "^4.8.1",
81+
"fast-jwt": "^2.1.0",
82+
"fastify": "^4.1.0",
8383
"fastify-plugin": "^3.0.1",
8484
"filenamify": "^4.3.0",
8585
"fs-extra": "^10.0.0",

src/v2/dao/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { CloudStorageConfigsModel } from "../../model/cloudStorage/CloudStorageC
2222
import { OAuthInfosModel } from "../../model/oauth/oauth-infos";
2323
import { OAuthSecretsModel } from "../../model/oauth/oauth-secrets";
2424
import { OAuthUsersModel } from "../../model/oauth/oauth-users";
25+
import { dataSource } from "../../thirdPartyService/TypeORMService";
2526

2627
class DAO<M extends Model> {
2728
public constructor(private readonly model: EntityTarget<M>) {}
@@ -117,16 +118,15 @@ class DAO<M extends Model> {
117118
}
118119

119120
public async update(
120-
t: EntityManager,
121+
t: EntityManager | null,
121122
updateData: QueryDeepPartialEntity<M>,
122123
where: FindOptionsWhere<M>,
123124
config?: {
124125
order?: [keyof M & string, "ASC" | "DESC"];
125126
limit?: number;
126127
},
127128
): Promise<void> {
128-
let sql = t
129-
.createQueryBuilder()
129+
let sql = (t ? t.createQueryBuilder() : dataSource.createQueryBuilder())
130130
.update(this.model)
131131
.set(updateData)
132132
.where(DAOUtils.softDelete(where))

src/v2/services/cloud-storage/__tests__/convert.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,41 @@ test(`${namespace} - start whiteboard projector - convertStep not none`, async a
301301
await releaseRunner();
302302
});
303303

304+
test.serial(`${namespace} - start whiteboard projector - failed`, async ava => {
305+
const stubAxios = sinon.stub(ax, "post").resolves({
306+
data: {
307+
uuid: undefined,
308+
},
309+
});
310+
311+
const { t, releaseRunner } = await useTransaction();
312+
313+
const fileUUID = v4();
314+
315+
const cloudStorageConvertSVC = new CloudStorageConvertService(ids(), t, fileUUID);
316+
317+
await ava.throwsAsync(
318+
() =>
319+
cloudStorageConvertSVC.startWhiteboardProjector(v4(), v4(), {
320+
region: Region.SG,
321+
convertStep: FileConvertStep.Converting,
322+
}),
323+
{
324+
instanceOf: FError,
325+
message: `${Status.Failed}: ${ErrorCode.FileConvertFailed}`,
326+
},
327+
);
328+
329+
const data = await cloudStorageFilesDAO.findOne(t, 'payload', {
330+
file_uuid: fileUUID,
331+
});
332+
333+
ava.is((data.payload as any)?.convertStep, FileConvertStep.Failed);
334+
335+
stubAxios.restore();
336+
await releaseRunner();
337+
});
338+
304339
test.serial(`${namespace} - start whiteboard projector - success`, async ava => {
305340
const { t, releaseRunner } = await useTransaction();
306341
const { createCloudStorageFiles } = testService(t);

src/v2/services/cloud-storage/convert.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ export class CloudStorageConvertService {
110110
const whiteboardConversionSVC = new WhiteboardConversionService(this.ids);
111111

112112
const taskUUID = await whiteboardConversionSVC.create(fileURL);
113+
if (!taskUUID) {
114+
await cloudStorageFilesDAO.update(
115+
// we don't want to rollback this action
116+
null,
117+
{
118+
payload: {
119+
convertStep: FileConvertStep.Failed,
120+
region: payload.region,
121+
},
122+
},
123+
{
124+
file_uuid: fileUUID,
125+
}
126+
)
127+
128+
throw new FError(ErrorCode.FileConvertFailed);
129+
}
130+
113131
const taskToken = WhiteboardTokenService.createTask(taskUUID);
114132

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

195213
const taskUUID = await whiteboardProjectorSVC.create(fileURL);
214+
if (!taskUUID) {
215+
await cloudStorageFilesDAO.update(
216+
// we don't want to rollback this action
217+
null,
218+
{
219+
payload: {
220+
convertStep: FileConvertStep.Failed,
221+
region: payload.region,
222+
},
223+
},
224+
{
225+
file_uuid: fileUUID,
226+
}
227+
)
228+
229+
throw new FError(ErrorCode.FileConvertFailed);
230+
}
231+
196232
const taskToken = WhiteboardTokenService.createTask(taskUUID);
197233

198234
await cloudStorageFilesDAO.update(

src/v2/services/whiteboard/conversion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class WhiteboardConversionService {
1212

1313
public constructor(private readonly ids: IDS) {}
1414

15-
public async create(resource: string): Promise<string> {
15+
public async create(resource: string): Promise<string | undefined> {
1616
const result = await ax.post<TaskCreated>(
1717
"https://api.netless.link/v5/services/conversion/tasks",
1818
{

src/v2/services/whiteboard/projector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class WhiteboardProjectorService {
1111

1212
public constructor(private readonly ids: IDS) {}
1313

14-
public async create(resource: string): Promise<string> {
14+
public async create(resource: string): Promise<string | undefined> {
1515
const { data } = await ax.post<TaskCreated>(
1616
"https://api.netless.link/v5/projector/tasks",
1717
{

0 commit comments

Comments
 (0)