debian-mirror-gitlab/app/models/project_export_job.rb

49 lines
1 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
class ProjectExportJob < ApplicationRecord
2023-03-04 22:38:38 +05:30
include EachBatch
EXPIRES_IN = 7.days
2020-04-08 14:13:33 +05:30
belongs_to :project
2022-08-13 15:12:31 +05:30
has_many :relation_exports, class_name: 'Projects::ImportExport::RelationExport'
2020-04-08 14:13:33 +05:30
validates :project, :jid, :status, presence: true
2023-03-04 22:38:38 +05:30
STATUS = {
queued: 0,
started: 1,
finished: 2,
failed: 3
}.freeze
scope :prunable, -> { where("updated_at < ?", EXPIRES_IN.ago) }
2020-04-08 14:13:33 +05:30
state_machine :status, initial: :queued do
event :start do
transition [:queued] => :started
end
event :finish do
transition [:started] => :finished
end
event :fail_op do
transition [:queued, :started] => :failed
end
2023-03-04 22:38:38 +05:30
state :queued, value: STATUS[:queued]
state :started, value: STATUS[:started]
state :finished, value: STATUS[:finished]
state :failed, value: STATUS[:failed]
end
class << self
def prune_expired_jobs
prunable.each_batch do |relation| # rubocop:disable Style/SymbolProc
relation.delete_all
end
end
2020-04-08 14:13:33 +05:30
end
end