Skip to content

Commit

Permalink
feat: clean binary merge logic
Browse files Browse the repository at this point in the history
  • Loading branch information
elrrrrrrr committed Jan 22, 2024
1 parent fb006e3 commit 24ae6a2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/core/entity/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ export class Task<T extends TaskBaseData = TaskBaseData> extends Entity {
return task;
}

public static needMergeWhenWaiting(type: Task['type']) {
return [ TaskType.SyncBinary, TaskType.SyncPackage ].includes(type);
}

start(): TaskUpdateCondition {
const condition = {
taskId: this.taskId,
Expand Down
6 changes: 0 additions & 6 deletions app/core/service/BinarySyncerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,7 @@ export class BinarySyncerService extends AbstractService {
return await this.nfsAdapter.getDownloadUrlOrStream(binary.storePath);
}

// SyncBinary 由定时任务每台单机定时触发,手动去重
// 添加 bizId 在 db 防止重复,记录 id 错误
public async createTask(binaryName: BinaryName, lastData?: any) {
const existsTask = await this.taskRepository.findTaskByTargetName(binaryName, TaskType.SyncBinary);
if (existsTask) {
return existsTask;
}
try {
return await this.taskService.createTask(Task.createSyncBinary(binaryName, lastData), false);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion app/core/service/TaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class TaskService extends AbstractService {
const existsTask = await this.taskRepository.findTaskByTargetName(task.targetName, task.type);

// 只在包同步场景下做任务合并,其余场景通过 bizId 来进行任务幂等
if (existsTask && [ TaskType.SyncPackage, TaskType.SyncBinary ].includes(task.type)) {
if (existsTask && Task.needMergeWhenWaiting(task.type)) {
// 在包同步场景,如果任务还未被触发,就不继续重复创建
// 如果任务正在执行,可能任务状态已更新,这种情况需要继续创建
if (existsTask.state === TaskState.Waiting) {
Expand Down

0 comments on commit 24ae6a2

Please sign in to comment.