Class: Packages::Nuget::UpdatePackageFromMetadataService

Inherits:
Object
  • Object
show all
Includes:
ExclusiveLeaseGuard, Gitlab::Utils::StrongMemoize
Defined in:
app/services/packages/nuget/update_package_from_metadata_service.rb

Constant Summary collapse

DEFAULT_LEASE_TIMEOUT =

used by ExclusiveLeaseGuard

1.hour.to_i.freeze
InvalidMetadataError =
Class.new(StandardError)

Instance Method Summary collapse

Methods included from ExclusiveLeaseGuard

#exclusive_lease, #lease_release?, #log_error, #release_lease, #renew_lease!, #try_obtain_lease

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(package_file) ⇒ UpdatePackageFromMetadataService

Returns a new instance of UpdatePackageFromMetadataService.


14
15
16
# File 'app/services/packages/nuget/update_package_from_metadata_service.rb', line 14

def initialize(package_file)
  @package_file = package_file
end

Instance Method Details

#executeObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/packages/nuget/update_package_from_metadata_service.rb', line 18

def execute
  raise InvalidMetadataError.new('package name and/or package version not found in metadata') unless valid_metadata?

  try_obtain_lease do
    @package_file.transaction do
      package = existing_package ? link_to_existing_package : update_linked_package

      update_package(package)

      # Updating file_name updates the path where the file is stored.
      # We must pass the file again so that CarrierWave can handle the update
      @package_file.update!(
        file_name: package_filename,
        file: @package_file.file
      )
    end
  end
end