blob: aa7bbffa7329817f57051401c44d5c51bc5fedb7 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# frozen_string_literal: true
module BulkImports
class FinishBatchedRelationExportWorker
include ApplicationWorker
idempotent!
data_consistency :always # rubocop:disable SidekiqLoadBalancing/WorkerDataConsistency
feature_category :importers
REENQUEUE_DELAY = 5.seconds
TIMEOUT = 6.hours
def perform(export_id)
@export = Export.find_by_id(export_id)
return unless export
return if export.finished? || export.failed?
return re_enqueue if export_in_progress?
return fail_export! if export_timeout?
finish_export!
end
private
attr_reader :export
def fail_export!
expire_cache!
export.batches.map(&:fail_op!)
export.fail_op!
end
def re_enqueue
self.class.perform_in(REENQUEUE_DELAY.ago, export.id)
end
def export_timeout?
export.updated_at < TIMEOUT.ago
end
def export_in_progress?
export.batches.any?(&:started?)
end
def finish_export!
expire_cache!
export.finish!
end
def expire_cache!
export.batches.each do |batch|
key = BulkImports::BatchedRelationExportService.cache_key(export.id, batch.id)
Gitlab::Cache::Import::Caching.expire(key, 0)
end
end
end
end
|