Commit bd2991b4 authored by Stan Hu's avatar Stan Hu

Use after_commit_queue to schedule import job immediately

parent fbe5bf76
...@@ -121,6 +121,8 @@ end ...@@ -121,6 +121,8 @@ end
# State machine # State machine
gem "state_machine", '~> 1.2.0' gem "state_machine", '~> 1.2.0'
# Run events after state machine commits
gem 'after_commit_queue'
# Issue tags # Issue tags
gem 'acts-as-taggable-on', '~> 3.4' gem 'acts-as-taggable-on', '~> 3.4'
......
...@@ -42,6 +42,8 @@ GEM ...@@ -42,6 +42,8 @@ GEM
acts-as-taggable-on (3.5.0) acts-as-taggable-on (3.5.0)
activerecord (>= 3.2, < 5) activerecord (>= 3.2, < 5)
addressable (2.3.8) addressable (2.3.8)
after_commit_queue (1.1.0)
rails (>= 3.0)
annotate (2.6.10) annotate (2.6.10)
activerecord (>= 3.2, <= 4.3) activerecord (>= 3.2, <= 4.3)
rake (~> 10.4) rake (~> 10.4)
...@@ -787,6 +789,7 @@ DEPENDENCIES ...@@ -787,6 +789,7 @@ DEPENDENCIES
activerecord-session_store (~> 0.1.0) activerecord-session_store (~> 0.1.0)
acts-as-taggable-on (~> 3.4) acts-as-taggable-on (~> 3.4)
addressable (~> 2.3.8) addressable (~> 2.3.8)
after_commit_queue
annotate (~> 2.6.0) annotate (~> 2.6.0)
asana (~> 0.0.6) asana (~> 0.0.6)
asciidoctor (~> 1.5.2) asciidoctor (~> 1.5.2)
......
...@@ -39,6 +39,7 @@ class Project < ActiveRecord::Base ...@@ -39,6 +39,7 @@ class Project < ActiveRecord::Base
include Gitlab::VisibilityLevel include Gitlab::VisibilityLevel
include Referable include Referable
include Sortable include Sortable
include AfterCommitQueue
extend Gitlab::ConfigHelper extend Gitlab::ConfigHelper
extend Enumerize extend Enumerize
...@@ -191,7 +192,7 @@ class Project < ActiveRecord::Base ...@@ -191,7 +192,7 @@ class Project < ActiveRecord::Base
state :finished state :finished
state :failed 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 after_transition any => :finished, do: :clear_import_data
end end
...@@ -275,15 +276,17 @@ class Project < ActiveRecord::Base ...@@ -275,15 +276,17 @@ class Project < ActiveRecord::Base
id && persisted? id && persisted?
end end
def schedule_add_import_job
run_after_commit(:add_import_job)
end
def add_import_job def add_import_job
# Schedule these jobs after 2 seconds to ensure DB changes to import_status
# are saved by the time the workers start
if forked? if forked?
unless RepositoryForkWorker.perform_in(2.seconds, id, forked_from_project.path_with_namespace, self.namespace.path) unless RepositoryForkWorker.perform_async(id, forked_from_project.path_with_namespace, self.namespace.path)
import_fail import_fail
end end
else else
RepositoryImportWorker.perform_in(2.seconds, id) RepositoryImportWorker.perform_async(id)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment