Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e4eac1ff
Commit
e4eac1ff
authored
Jun 01, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don’t schedule workers from inside transactions
parent
a9dbda86
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
20 deletions
+32
-20
app/models/ci/build.rb
app/models/ci/build.rb
+8
-2
app/models/commit_status.rb
app/models/commit_status.rb
+4
-3
app/models/key.rb
app/models/key.rb
+4
-5
app/models/lfs_objects_project.rb
app/models/lfs_objects_project.rb
+1
-2
app/models/namespace.rb
app/models/namespace.rb
+4
-1
app/models/project.rb
app/models/project.rb
+3
-1
app/services/projects/destroy_service.rb
app/services/projects/destroy_service.rb
+8
-6
No files found.
app/models/ci/build.rb
View file @
e4eac1ff
...
@@ -47,8 +47,8 @@ module Ci
...
@@ -47,8 +47,8 @@ module Ci
before_destroy
{
unscoped_project
}
before_destroy
{
unscoped_project
}
after_create
:execute_hooks
after_create
:execute_hooks
after_
save
:update_project_statistics
,
if: :artifacts_size_changed?
after_
commit
:update_project_statistics_after_save
,
on:
[
:create
,
:update
]
after_
destroy
:update_project_statistics
after_
commit
:update_project_statistics
,
on: :destroy
class
<<
self
class
<<
self
# This is needed for url_for to work,
# This is needed for url_for to work,
...
@@ -491,5 +491,11 @@ module Ci
...
@@ -491,5 +491,11 @@ module Ci
ProjectCacheWorker
.
perform_async
(
project_id
,
[],
[
:build_artifacts_size
])
ProjectCacheWorker
.
perform_async
(
project_id
,
[],
[
:build_artifacts_size
])
end
end
def
update_project_statistics_after_save
if
previous_changes
.
include?
(
'artifacts_size'
)
update_project_statistics
end
end
end
end
end
end
app/models/commit_status.rb
View file @
e4eac1ff
...
@@ -83,14 +83,15 @@ class CommitStatus < ActiveRecord::Base
...
@@ -83,14 +83,15 @@ class CommitStatus < ActiveRecord::Base
next
if
transition
.
loopback?
next
if
transition
.
loopback?
commit_status
.
run_after_commit
do
commit_status
.
run_after_commit
do
pipeline
.
try
do
|
pipeline
|
if
pipeline
if
complete?
||
manual?
if
complete?
||
manual?
PipelineProcessWorker
.
perform_async
(
pipeline
.
id
)
PipelineProcessWorker
.
perform_async
(
pipeline
.
id
)
else
else
PipelineUpdateWorker
.
perform_async
(
pipeline
.
id
)
PipelineUpdateWorker
.
perform_async
(
pipeline
.
id
)
end
end
ExpireJobCacheWorker
.
perform_async
(
commit_status
.
id
)
end
end
ExpireJobCacheWorker
.
perform_async
(
commit_status
.
id
)
end
end
end
end
...
...
app/models/key.rb
View file @
e4eac1ff
require
'digest/md5'
require
'digest/md5'
class
Key
<
ActiveRecord
::
Base
class
Key
<
ActiveRecord
::
Base
include
AfterCommitQueue
include
Sortable
include
Sortable
LAST_USED_AT_REFRESH_TIME
=
1
.
day
.
to_i
LAST_USED_AT_REFRESH_TIME
=
1
.
day
.
to_i
...
@@ -25,10 +24,10 @@ class Key < ActiveRecord::Base
...
@@ -25,10 +24,10 @@ class Key < ActiveRecord::Base
delegate
:name
,
:email
,
to: :user
,
prefix:
true
delegate
:name
,
:email
,
to: :user
,
prefix:
true
after_c
reate
:add_to_shell
after_c
ommit
:add_to_shell
,
on: :create
after_c
reate
:notify_user
after_c
ommit
:notify_user
,
on: :create
after_create
:post_create_hook
after_create
:post_create_hook
after_
destroy
:remove_from_shell
after_
commit
:remove_from_shell
,
on: :destroy
after_destroy
:post_destroy_hook
after_destroy
:post_destroy_hook
def
key
=
(
value
)
def
key
=
(
value
)
...
@@ -93,6 +92,6 @@ class Key < ActiveRecord::Base
...
@@ -93,6 +92,6 @@ class Key < ActiveRecord::Base
end
end
def
notify_user
def
notify_user
run_after_commit
{
NotificationService
.
new
.
new_key
(
self
)
}
NotificationService
.
new
.
new_key
(
self
)
end
end
end
end
app/models/lfs_objects_project.rb
View file @
e4eac1ff
...
@@ -6,8 +6,7 @@ class LfsObjectsProject < ActiveRecord::Base
...
@@ -6,8 +6,7 @@ class LfsObjectsProject < ActiveRecord::Base
validates
:lfs_object_id
,
uniqueness:
{
scope:
[
:project_id
],
message:
"already exists in project"
}
validates
:lfs_object_id
,
uniqueness:
{
scope:
[
:project_id
],
message:
"already exists in project"
}
validates
:project_id
,
presence:
true
validates
:project_id
,
presence:
true
after_create
:update_project_statistics
after_commit
:update_project_statistics
,
on:
[
:create
,
:destroy
]
after_destroy
:update_project_statistics
private
private
...
...
app/models/namespace.rb
View file @
e4eac1ff
...
@@ -6,6 +6,7 @@ class Namespace < ActiveRecord::Base
...
@@ -6,6 +6,7 @@ class Namespace < ActiveRecord::Base
include
Gitlab
::
ShellAdapter
include
Gitlab
::
ShellAdapter
include
Gitlab
::
CurrentSettings
include
Gitlab
::
CurrentSettings
include
Routable
include
Routable
include
AfterCommitQueue
# Prevent users from creating unreasonably deep level of nesting.
# Prevent users from creating unreasonably deep level of nesting.
# The number 20 was taken based on maximum nesting level of
# The number 20 was taken based on maximum nesting level of
...
@@ -242,9 +243,11 @@ class Namespace < ActiveRecord::Base
...
@@ -242,9 +243,11 @@ class Namespace < ActiveRecord::Base
# Remove namespace directroy async with delay so
# Remove namespace directroy async with delay so
# GitLab has time to remove all projects first
# GitLab has time to remove all projects first
run_after_commit
do
GitlabShellWorker
.
perform_in
(
5
.
minutes
,
:rm_namespace
,
repository_storage_path
,
new_path
)
GitlabShellWorker
.
perform_in
(
5
.
minutes
,
:rm_namespace
,
repository_storage_path
,
new_path
)
end
end
end
end
end
remove_exports!
remove_exports!
end
end
...
...
app/models/project.rb
View file @
e4eac1ff
...
@@ -471,7 +471,9 @@ class Project < ActiveRecord::Base
...
@@ -471,7 +471,9 @@ class Project < ActiveRecord::Base
end
end
def
reset_cache_and_import_attrs
def
reset_cache_and_import_attrs
run_after_commit
do
ProjectCacheWorker
.
perform_async
(
self
.
id
)
ProjectCacheWorker
.
perform_async
(
self
.
id
)
end
self
.
import_data
&
.
destroy
self
.
import_data
&
.
destroy
end
end
...
...
app/services/projects/destroy_service.rb
View file @
e4eac1ff
...
@@ -7,12 +7,10 @@ module Projects
...
@@ -7,12 +7,10 @@ module Projects
DELETED_FLAG
=
'+deleted'
.
freeze
DELETED_FLAG
=
'+deleted'
.
freeze
def
async_execute
def
async_execute
project
.
transaction
do
project
.
update_attribute
(
:pending_delete
,
true
)
project
.
update_attribute
(
:pending_delete
,
true
)
job_id
=
ProjectDestroyWorker
.
perform_async
(
project
.
id
,
current_user
.
id
,
params
)
job_id
=
ProjectDestroyWorker
.
perform_async
(
project
.
id
,
current_user
.
id
,
params
)
Rails
.
logger
.
info
(
"User
#{
current_user
.
id
}
scheduled destruction of project
#{
project
.
path_with_namespace
}
with job ID
#{
job_id
}
"
)
Rails
.
logger
.
info
(
"User
#{
current_user
.
id
}
scheduled destruction of project
#{
project
.
path_with_namespace
}
with job ID
#{
job_id
}
"
)
end
end
end
def
execute
def
execute
return
false
unless
can?
(
current_user
,
:remove_project
,
project
)
return
false
unless
can?
(
current_user
,
:remove_project
,
project
)
...
@@ -62,7 +60,11 @@ module Projects
...
@@ -62,7 +60,11 @@ module Projects
if
gitlab_shell
.
mv_repository
(
project
.
repository_storage_path
,
path
,
new_path
)
if
gitlab_shell
.
mv_repository
(
project
.
repository_storage_path
,
path
,
new_path
)
log_info
(
"Repository
\"
#{
path
}
\"
moved to
\"
#{
new_path
}
\"
"
)
log_info
(
"Repository
\"
#{
path
}
\"
moved to
\"
#{
new_path
}
\"
"
)
GitlabShellWorker
.
perform_in
(
5
.
minutes
,
:remove_repository
,
project
.
repository_storage_path
,
new_path
)
project
.
run_after_commit
do
# self is now project
GitlabShellWorker
.
perform_in
(
5
.
minutes
,
:remove_repository
,
self
.
repository_storage_path
,
new_path
)
end
else
else
false
false
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment