Merge pull request #2590 from biosistemika/SCI-4628-schedule-snapshots-for-locked-tasks

[SCI-4628] moving snapshot provisioning logic into repository model, ma…
This commit is contained in:
Alex Kriuchykhin 2020-05-21 09:53:04 +02:00 committed by GitHub
commit bc70ceb120
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 10 deletions

View file

@ -31,15 +31,7 @@ class MyModuleRepositorySnapshotsController < ApplicationController
end
def create
repository_snapshot = @repository.dup.becomes(RepositorySnapshot)
repository_snapshot.assign_attributes(type: RepositorySnapshot.name,
original_repository: @repository,
my_module: @my_module,
created_by: current_user)
repository_snapshot.provisioning!
repository_snapshot.reload
RepositorySnapshotProvisioningJob.perform_later(repository_snapshot)
repository_snapshot = @repository.provision_snapshot(@my_module, current_user)
render json: {
html: render_to_string(partial: 'my_modules/repositories/full_view_version',

View file

@ -191,4 +191,17 @@ class Repository < RepositoryBase
importer = RepositoryImportParser::Importer.new(sheet, mappings, user, self)
importer.run
end
def provision_snapshot(my_module, created_by = nil)
created_by ||= self.created_by
repository_snapshot = dup.becomes(RepositorySnapshot)
repository_snapshot.assign_attributes(type: RepositorySnapshot.name,
original_repository: self,
my_module: my_module,
created_by: created_by)
repository_snapshot.provisioning!
repository_snapshot.reload
RepositorySnapshotProvisioningJob.perform_later(repository_snapshot)
repository_snapshot
end
end

View file

@ -11,7 +11,7 @@ class RepositorySnapshot < RepositoryBase
validates :name, presence: true, length: { maximum: Constants::NAME_MAX_LENGTH }
validates :status, presence: true
validate :only_one_selected_for_my_module
validate :only_one_selected_for_my_module, if: ->(obj) { obj.changed.include? :selected }
def default_columns_count
Constants::REPOSITORY_SNAPSHOT_TABLE_DEFAULT_STATE['length']