summaryrefslogtreecommitdiff
path: root/app/workers/single_repository_check_worker.rb
blob: 6257f382d863f80c3928fa890620eeae0f5b0211 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class SingleRepositoryCheckWorker
  include Sidekiq::Worker

  sidekiq_options retry: false

  def perform(project_id)
    project = Project.find(project_id)
    project.update_columns(
      last_repository_check_failed: !check(project),
      last_repository_check_at: Time.now,
    )
  end

  private

  def check(project)
    [project.repository, project.wiki.repository].all? do |repository|
      git_fsck(repository.path_to_repo)
    end
  end

  def git_fsck(path)
    cmd = %W(nice git --git-dir=#{path} fsck)
    output, status = Gitlab::Popen.popen(cmd)

    if status.zero?
      true
    else
      Gitlab::RepositoryCheckLogger.error("command failed: #{cmd.join(' ')}\n#{output}")
      false
    end
  end
end