How to delete jobs from database which files are lost?

We have some lost job.log file on our gitlab server.
I checked it via gitlab-rake gitlab:artifacts:check VERBOSE=True
there are some records like this: - Job artifact: 558840: #<Errno::ENOENT: No such file or directory @ rb_sysopen - /home/git/artifacts/b5/1e/b51e45a12fbae3d0ee2bf77f1a4f80cbf642e2b4d1c237d2c0f7053a54f6b388/2019_05_13/1399519/558840/job.log>
because it i can’t do artifacts migrate task, after starting the migration I get an error and the task stops: Failed to transfer artifact of type trace and ID 476 with error: No such file or directory @ rb_sysopen - /home/git/artifacts/40/e4/40e485376e18da6155ec4830fe17aed6d527b3e7fc0d4bb69f7f70c9c9b52f9e/2018_09_25/716128/476/job.log

The question is - how to delete all informarion about job.log and jobs artifacts from DB for be able to do artifacts migration

Solution (by Dmitry Chepurovskiy) (run in gitlab-rails console):

Ci::JobArtifact.where(file_store: [nil, ::JobArtifactUploader::Store::LOCAL]).find_in_batches do |batch|
  batch.each { |artifact|
begin
  artifact.open
rescue Errno::ENOENT => e
  puts "Artifact #{artifact.id} corrupted, deleting"
  artifact.destroy
end
  }
  #sleep(1)
end