Class: BulkImports::BatchedRelationExportService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/bulk_imports/batched_relation_export_service.rb

Constant Summary collapse

BATCH_SIZE =
1000
BATCH_CACHE_KEY =
'bulk_imports/batched_relation_export/%{export_id}/%{batch_id}'
CACHE_DURATION =
4.hours

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, portable, relation, jid) ⇒ BatchedRelationExportService

Returns a new instance of BatchedRelationExportService.



15
16
17
18
19
20
21
# File 'app/services/bulk_imports/batched_relation_export_service.rb', line 15

def initialize(user, portable, relation, jid)
  @user = user
  @portable = portable
  @relation = relation
  @resolved_relation = portable.public_send(relation) # rubocop:disable GitlabSecurity/PublicSend
  @jid = jid
end

Class Method Details

.cache_key(export_id, batch_id) ⇒ Object



11
12
13
# File 'app/services/bulk_imports/batched_relation_export_service.rb', line 11

def self.cache_key(export_id, batch_id)
  Kernel.format(BATCH_CACHE_KEY, export_id: export_id, batch_id: batch_id)
end

Instance Method Details

#executeObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/bulk_imports/batched_relation_export_service.rb', line 23

def execute
  return finish_export! if batches_count == 0

  start_export!
  export.batches.destroy_all # rubocop: disable Cop/DestroyAll
  enqueue_batch_exports
rescue StandardError => e
  fail_export!(e)
ensure
  FinishBatchedRelationExportWorker.perform_async(export.id)
end