Class: BulkImports::RelationBatchExportWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, Gitlab::Utils::StrongMemoize, Sidekiq::InterruptionsExhausted
Defined in:
app/workers/bulk_imports/relation_batch_export_worker.rb

Constant Summary collapse

PERFORM_DELAY =
1.minute

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY_PER_DB, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::LOAD_BALANCED_DATA_CONSISTENCIES, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Class Method Details

.perform_failure(job, exception) ⇒ Object



29
30
31
32
33
34
35
36
# File 'app/workers/bulk_imports/relation_batch_export_worker.rb', line 29

def self.perform_failure(job, exception)
  batch = BulkImports::ExportBatch.find(job['args'][1])
  portable = batch.export.portable

  Gitlab::ErrorTracking.track_exception(exception, portable_id: portable.id, portable_type: portable.class.name)

  batch.update!(status_event: 'fail_op', error: exception.message.truncate(255))
end

Instance Method Details

#max_exports_already_running?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/workers/bulk_imports/relation_batch_export_worker.rb', line 52

def max_exports_already_running?
  BulkImports::ExportBatch.started_and_not_timed_out.limit(max_exports).count == max_exports
end

#perform(user_id, batch_id) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/workers/bulk_imports/relation_batch_export_worker.rb', line 38

def perform(user_id, batch_id)
  @user = User.find(user_id)
  @batch = BulkImports::ExportBatch.find(batch_id)

  return re_enqueue_job(@user, @batch) if !@batch.started? && max_exports_already_running?

  (:relation, @batch.export.relation)
  (:batch_number, @batch.batch_number)

  RelationBatchExportService.new(@user, @batch).execute

  (:objects_count, @batch.objects_count)
end

#re_enqueue_job(user, batch) ⇒ Object



60
61
62
63
64
65
# File 'app/workers/bulk_imports/relation_batch_export_worker.rb', line 60

def re_enqueue_job(user, batch)
  reset_cache_timeout(batch)
  (:re_enqueue, true)

  self.class.perform_in(PERFORM_DELAY, user.id, batch.id)
end

#reset_cache_timeout(batch) ⇒ Object



67
68
69
70
71
# File 'app/workers/bulk_imports/relation_batch_export_worker.rb', line 67

def reset_cache_timeout(batch)
  cache_service = BulkImports::BatchedRelationExportService
  cache_key = cache_service.cache_key(batch.export_id, batch.id)
  Gitlab::Cache::Import::Caching.expire(cache_key, cache_service::CACHE_DURATION.to_i)
end