forgeplus/app/models/mirror.rb

38 lines
1.0 KiB
Ruby
Raw Normal View History

2020-11-23 15:35:03 +08:00
# == Schema Information
#
# Table name: mirrors
#
# id :integer not null, primary key
# repo_id :integer
# status :integer default("0"), not null
# interval :integer
# next_update_time :datetime
# created_at :datetime not null
# updated_at :datetime not null
# sync_num :integer default("1")
#
2020-05-18 18:25:50 +08:00
class Mirror < ApplicationRecord
# 0 - succeeded, 1 - waiting, 2 - failed
2020-06-29 16:05:57 +08:00
# 0: 同步镜像成功1: 正在同步镜像2: 同步失败; 默认值为0
2020-05-18 18:25:50 +08:00
enum status: { succeeded: 0, waiting: 1, failed: 2 }
2021-09-15 11:28:38 +08:00
# after_update :websocket_boardcast, if: :saved_change_to_status?
2020-05-18 18:25:50 +08:00
2020-07-07 16:08:10 +08:00
belongs_to :repository, foreign_key: :repo_id
2020-05-18 18:25:50 +08:00
def set_status!(status=Mirror.statuses[:succeeded])
2020-06-03 15:59:53 +08:00
update_column(:status, status)
2020-05-18 18:25:50 +08:00
end
def numerical_for_status
self.class.name.constantize.statuses["#{self.status}"]
end
2020-07-07 16:08:10 +08:00
private
def websocket_boardcast
BroadcastMirrorRepoMsgJob.perform_later(self.repository.id)
end
2020-05-18 18:25:50 +08:00
end