Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Feb 10, 2024
1 parent 6f15101 commit b5d610a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/online_migrations/background_migrations/migration_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,27 @@ def enqueue_background_migration(migration_name, *arguments, **options)
migration
end

def ensure_background_migration_succeeded(migration_name, arguments: nil)
migration_name = migration_name.name if migration_name.is_a?(Class)

configuration = { migration_name: migration_name }

if arguments
arguments = Array(arguments)
migration = Migration.for_migration_name(migration_name).first
configuration[:arguments] = arguments.to_json
else
migration = Migration.for_migration_name(migration_name).first
end

if migration.nil?
Utils.say("Could not find background migration for the given configuration: #{configuration}")
elsif !migration.succeeded?
raise "Expected background migration for the given configuration to be marked as 'succeeded', "\
"but it is '#{migration.status}': #{configuration}"
end
end

# @private
def create_background_migration(migration_name, *arguments, **options)
options.assert_valid_keys(:batch_column_name, :min_value, :max_value, :batch_size, :sub_batch_size,
Expand Down
5 changes: 5 additions & 0 deletions test/schema_statements/misc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ def test_run_background_migrations_inline_configured_to_custom_proc
assert_nil user.reload.admin
end

def test_ensure_background_migration_succeeded
m = @connection.enqueue_background_migration("MakeAllNonAdmins")
assert m.succeeded?
end

def test_disable_statement_timeout
prev_value = get_statement_timeout
set_statement_timeout(10)
Expand Down

0 comments on commit b5d610a

Please sign in to comment.