diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-09-25 11:15:03 +0000 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-09-28 22:42:18 -0400 |
commit | df1a235f230b7acd32508510ad8137593669b91e (patch) | |
tree | 19c37188fa1dd5c5a7eb7a81402b011e84fe9ffd | |
parent | 6249459cfd9e333b7555ad0662ed31039737ea52 (diff) | |
download | gitlab-ce-df1a235f230b7acd32508510ad8137593669b91e.tar.gz |
Merge branch 'fix-stuck-forked-project-import' into 'master'
Fix bug where projects would appear to be stuck in the forked import state
A race condition existed between when Rails committed the `import_status` to
`started` and when the Sidekiq worker forked a project. If this fork were quick,
it's possible that the worker would attempt to move into the `finished` state
before the `started` state took effect.
As mentioned in https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting#cannot-find-modelname-with-id12345,
we can either delay the worker to ensure the DB has a chance to update, or use the nice `after_commit_queue` gem to schedule the task after the state machine commit. See:
* https://github.com/pluginaweek/state_machine/issues/191
* https://github.com/shellycloud/after_commit_queue
Closes #2736
See merge request !1434
-rw-r--r-- | CHANGELOG | 13 | ||||
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 3 | ||||
-rw-r--r-- | app/models/project.rb | 9 |
4 files changed, 25 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG index 567bb4d7be1..7fc7295c912 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,19 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.0.3 (unreleased) v 8.0.2 +v 8.1.0 (unreleased) + - Fix bug where projects would appear to be stuck in the forked import state (Stan Hu) + - Show CI status on all pages where commits list is rendered + - Automatically enable CI when push .gitlab-ci.yml file to repository + - Move CI charts to project graphs area + - Fix cases where Markdown did not render links in activity feed (Stan Hu) + - Add first and last to pagination (Zeger-Jan van de Weg) + - Show CI status on commit page + - Show CI status on Your projects page and Starred projects page + - Remove "Continuous Integration" page from dashboard + - Add notes and SSL verification entries to hook APIs (Ben Boeckel) + +v 8.0.2 (unreleased) - Fix default avatar not rendering in network graph (Stan Hu) - Skip check_initd_configured_correctly on omnibus installs - Prevent double-prefixing of help page paths @@ -121,6 +121,8 @@ end # State machine gem "state_machine", '~> 1.2.0' +# Run events after state machine commits +gem 'after_commit_queue' # Issue tags gem 'acts-as-taggable-on', '~> 3.4' diff --git a/Gemfile.lock b/Gemfile.lock index 3c16251497d..56db3f61985 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,8 @@ GEM acts-as-taggable-on (3.5.0) activerecord (>= 3.2, < 5) addressable (2.3.8) + after_commit_queue (1.1.0) + rails (>= 3.0) annotate (2.6.10) activerecord (>= 3.2, <= 4.3) rake (~> 10.4) @@ -787,6 +789,7 @@ DEPENDENCIES activerecord-session_store (~> 0.1.0) acts-as-taggable-on (~> 3.4) addressable (~> 2.3.8) + after_commit_queue annotate (~> 2.6.0) asana (~> 0.0.6) asciidoctor (~> 1.5.2) diff --git a/app/models/project.rb b/app/models/project.rb index 1a5c1c978c9..57c5f7369d7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -39,6 +39,7 @@ class Project < ActiveRecord::Base include Gitlab::VisibilityLevel include Referable include Sortable + include AfterCommitQueue extend Gitlab::ConfigHelper extend Enumerize @@ -191,7 +192,7 @@ class Project < ActiveRecord::Base state :finished state :failed - after_transition any => :started, do: :add_import_job + after_transition any => :started, do: :schedule_add_import_job after_transition any => :finished, do: :clear_import_data end @@ -275,13 +276,17 @@ class Project < ActiveRecord::Base id && persisted? end + def schedule_add_import_job + run_after_commit(:add_import_job) + end + def add_import_job if forked? unless RepositoryForkWorker.perform_async(id, forked_from_project.path_with_namespace, self.namespace.path) import_fail end else - RepositoryImportWorker.perform_in(2.seconds, id) + RepositoryImportWorker.perform_async(id) end end |