Class: Gitlab::BackgroundMigration::RemoteDevelopment::BmCreateDesiredConfig
- Inherits:
-
Object
- Object
- Gitlab::BackgroundMigration::RemoteDevelopment::BmCreateDesiredConfig
- Defined in:
- lib/gitlab/background_migration/remote_development/bm_create_desired_config.rb
Overview
rubocop:disable Migration/BatchedMigrationBaseClass – This is not a migration file class so we do not need to inherit from BatchedMigrationJob
Class Method Summary collapse
- .create_and_save(workspace_id:, dry_run: false) ⇒ Void
- .logger ⇒ Gitlab::BackgroundMigration::Logger
-
.validate_and_create_workspace_agentk_state(workspace:, desired_config:, logger:, dry_run:) ⇒ Void
rubocop:disable Metrics/MethodLength – need it big.
Class Method Details
.create_and_save(workspace_id:, dry_run: false) ⇒ Void
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gitlab/background_migration/remote_development/bm_create_desired_config.rb', line 10 def self.create_and_save(workspace_id:, dry_run: false) workspace = RemoteDevelopment::Models::BmWorkspace.find(workspace_id) result = BackgroundMigration::RemoteDevelopment::WorkspaceOperations::Create::DesiredConfig::BmMain.main( { params: { agent: workspace.agent }, workspace: workspace, logger: logger } ) validate_and_create_workspace_agentk_state( workspace: workspace, desired_config: result[:desired_config], logger: logger, dry_run: dry_run ) end |
.logger ⇒ Gitlab::BackgroundMigration::Logger
83 84 85 |
# File 'lib/gitlab/background_migration/remote_development/bm_create_desired_config.rb', line 83 def self.logger @logger ||= ::Gitlab::BackgroundMigration::Logger.build end |
.validate_and_create_workspace_agentk_state(workspace:, desired_config:, logger:, dry_run:) ⇒ Void
rubocop:disable Metrics/MethodLength – need it big
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gitlab/background_migration/remote_development/bm_create_desired_config.rb', line 37 def self.validate_and_create_workspace_agentk_state(workspace:, desired_config:, logger:, dry_run:) if dry_run puts "For workspace_id #{workspace.id}" puts "Valid desired_config? #{desired_config.valid?}" desired_config.errors..each do || puts end end unless desired_config.valid? logger.error( message: "desired_config is invalid", error_type: "workspace_agentk_state_migration_error", workspace_id: workspace.id, validation_error: desired_config.errors. ) return end if dry_run # noinspection RubyArgCount -- RubyMine does not recognize the fields workspace_agentk_state = RemoteDevelopment::Models::BmWorkspaceAgentkState.new( workspace_id: workspace.id, project_id: workspace.project_id, desired_config: desired_config.symbolized_desired_config_array ) puts "Valid state model? #{workspace_agentk_state.valid?}" workspace_agentk_state.errors..each do || puts end else RemoteDevelopment::Models::BmWorkspaceAgentkState.upsert( { workspace_id: workspace.id, project_id: workspace.project_id, desired_config: desired_config.symbolized_desired_config_array }, unique_by: :workspace_id ) end end |