online_migrations 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ecf0ad3b1c2bc1992e9ec205018212b4d3c663f2a3040271a0cce45d4b9f60c
4
- data.tar.gz: fcc3a3ac5b96fc3bd893f251949969794ebde738e5f663eb367fd191fa50784d
3
+ metadata.gz: 493a3f1a84eb30974c533f81ca5baf8b739d69d4ec6e30810d891284791632f1
4
+ data.tar.gz: 9dae1370ea3073146888d3757314bac6c8e968c5e35a2c2be345f3617f610881
5
5
  SHA512:
6
- metadata.gz: c5a92bde9892d9f7bf545248d359527c9fac1a41b31e6eabf34f0da0a1342fdfc9e54ccc853aba6e35414d368328979d7b445246f71e72e0ac09cce80ad8a02f
7
- data.tar.gz: d244cb531e3e2f58d140e75af1f8fc571a272d9d188d87f0e52d89b7efbc7233eb4c1df7bac63fe32d1e7b79643e1202872b951f1fcfc2b8ca5fa9c3abdc7746
6
+ metadata.gz: d40cae89f1be37a97567d7bb05d1ded17479ce89b9783ed0c606d6bdfdec2d940d251de4de66557af774fc88e1262ae492539fe3fae5f4cb105d88526e7315d3
7
+ data.tar.gz: 26316851d405210a67576ea0ae35ba0419574832aacc43a2f0ddd00a8f22223f0d1ed73ff1635f6f9aa4168877c48aebb56d0f93f05472b531d80f3fc19881e9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## master (unreleased)
2
2
 
3
+ ## 0.22.0 (2025-01-03)
4
+
5
+ - Make background data migrations scheduler run a single migration at a time
6
+
7
+ This is similar to background schema migrations scheduler's behavior.
8
+ Running multiple migrations at a time can cause unneeded database load and other bad effects.
9
+
10
+ - Add `#pausable?`, `#can_be_cancelled?` and `#can_be_paused?` helpers to background migrations
11
+
3
12
  ## 0.21.0 (2024-12-09)
4
13
 
5
14
  - Fix `add_foreign_key` when referencing same table via different columns
@@ -110,6 +110,18 @@ module OnlineMigrations
110
110
  end
111
111
  alias cancel cancelled!
112
112
 
113
+ def pausable?
114
+ true
115
+ end
116
+
117
+ def can_be_paused?
118
+ enqueued? || running?
119
+ end
120
+
121
+ def can_be_cancelled?
122
+ !succeeded? && !cancelled?
123
+ end
124
+
113
125
  def last_job
114
126
  migration_jobs.order(:max_value).last
115
127
  end
@@ -3,9 +3,10 @@
3
3
  module OnlineMigrations
4
4
  module BackgroundMigrations
5
5
  # Class responsible for scheduling background migrations.
6
- # It selects runnable background migrations and runs them one step (one batch) at a time.
6
+ #
7
+ # It selects a single runnable background migration and runs it one step (one batch) at a time.
7
8
  # A migration is considered runnable if it is not completed and the time interval between
8
- # successive runs has passed.
9
+ # successive runs has passed.
9
10
  #
10
11
  # Scheduler should be configured to run periodically, for example, via cron.
11
12
  # @example Run via whenever
@@ -22,18 +23,13 @@ module OnlineMigrations
22
23
  # Runs Scheduler
23
24
  def run
24
25
  active_migrations = Migration.runnable.active.queue_order
25
- runnable_migrations = active_migrations.select(&:interval_elapsed?)
26
+ runnable_migration = active_migrations.select(&:interval_elapsed?).first
26
27
 
27
- runnable_migrations.each do |migration|
28
- run_migration_job(migration)
29
- end
30
- end
31
-
32
- private
33
- def run_migration_job(migration)
34
- runner = MigrationRunner.new(migration)
28
+ if runnable_migration
29
+ runner = MigrationRunner.new(runnable_migration)
35
30
  runner.run_migration_job
36
31
  end
32
+ end
37
33
  end
38
34
  end
39
35
  end
@@ -94,6 +94,18 @@ module OnlineMigrations
94
94
  end
95
95
  alias cancel cancelled!
96
96
 
97
+ def pausable?
98
+ false
99
+ end
100
+
101
+ def can_be_paused?
102
+ false
103
+ end
104
+
105
+ def can_be_cancelled?
106
+ !succeeded? && !cancelled?
107
+ end
108
+
97
109
  # Returns the progress of the background schema migration.
98
110
  #
99
111
  # @return [Float] value in range from 0.0 to 100.0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlineMigrations
4
- VERSION = "0.21.0"
4
+ VERSION = "0.22.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: online_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fatkodima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-09 00:00:00.000000000 Z
11
+ date: 2025-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord