forked from Trustie/forgeplus
fix: mirror broadcast error and retry
This commit is contained in:
parent
8c60ce1d76
commit
8a02981a2e
|
@ -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
|
||||
|
|
|
@ -16,5 +16,6 @@ class MigrateRemoteRepositoryJob < ApplicationJob
|
|||
else
|
||||
repo&.mirror&.failed!
|
||||
end
|
||||
BroadcastMirrorRepoMsgJob.perform_later(repo.id) unless repo&.mirror.waiting?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue