fix: mirror broadcast error and retry

This commit is contained in:
yystopf 2021-09-15 11:28:38 +08:00
parent 8c60ce1d76
commit 8a02981a2e
4 changed files with 21 additions and 2 deletions

View File

@ -18,12 +18,29 @@ class BroadcastMirrorRepoMsgJob < ApplicationJob
id: project.id,
type: project.numerical_for_project_type
}
# 新增失败重试机制, 重试三次
result = broadcast(project, json_data)
if result == 0
count = 3
while count > 0
result = broadcast(project, json_data)
if result > 0
break
end
count -= 1
end
end
end
def broadcast(project, json_data)
puts "############ broadcast start.......... "
puts "############ broadcast channel_name: channel_room_#{project.id}"
puts "############ broadcast project data: #{json_data} "
cable_result = ActionCable.server.broadcast "channel_room_#{project.id}", project: json_data
puts "############ broadcast result: #{cable_result == 1 ? 'successed' : 'failed'} "
puts "############ broadcast result: #{cable_result > 0 ? 'successed' : 'failed'} "
return cable_result
end
end

View File

@ -16,5 +16,6 @@ class MigrateRemoteRepositoryJob < ApplicationJob
else
repo&.mirror&.failed!
end
BroadcastMirrorRepoMsgJob.perform_later(repo.id) unless repo&.mirror.waiting?
end
end

View File

@ -26,6 +26,7 @@ class SyncMirroredRepositoryJob < ApplicationJob
result = Gitea::Repository::SyncMirroredService.call(repo.owner.login,
repo.identifier, token: user.gitea_token)
repo&.mirror.set_status! if result[:status] === 200
BroadcastMirrorRepoMsgJob.perform_later(repo.id) unless repo&.mirror.waiting?
end
end

View File

@ -18,7 +18,7 @@ class Mirror < ApplicationRecord
# 0: 同步镜像成功1: 正在同步镜像2: 同步失败; 默认值为0
enum status: { succeeded: 0, waiting: 1, failed: 2 }
after_update :websocket_boardcast, if: :saved_change_to_status?
# after_update :websocket_boardcast, if: :saved_change_to_status?
belongs_to :repository, foreign_key: :repo_id