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
e9e8a2f6
Commit
e9e8a2f6
authored
Dec 18, 2015
by
Kamil Trzcinski
Committed by
James Edwards-Jones
Jan 31, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Asynchronously remove pages
parent
9ff381c4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
10 deletions
+30
-10
app/models/project.rb
app/models/project.rb
+5
-1
app/services/update_pages_service.rb
app/services/update_pages_service.rb
+1
-1
app/workers/pages_worker.rb
app/workers/pages_worker.rb
+10
-1
spec/workers/pages_worker_spec.rb
spec/workers/pages_worker_spec.rb
+14
-7
No files found.
app/models/project.rb
View file @
e9e8a2f6
...
@@ -1186,7 +1186,11 @@ class Project < ActiveRecord::Base
...
@@ -1186,7 +1186,11 @@ class Project < ActiveRecord::Base
end
end
def
remove_pages
def
remove_pages
FileUtils
.
rm_r
(
pages_path
,
force:
true
)
temp_path
=
"
#{
path
}
.
#{
SecureRandom
.
hex
}
"
if
Gitlab
::
PagesTransfer
.
new
.
rename_project
(
path
,
temp_path
,
namespace
.
path
)
PagesWorker
.
perform_in
(
5
.
minutes
,
:remove
,
namespace
.
path
,
temp_path
)
end
end
end
def
wiki
def
wiki
...
...
app/services/update_pages_service.rb
View file @
e9e8a2f6
...
@@ -10,6 +10,6 @@ class UpdatePagesService
...
@@ -10,6 +10,6 @@ class UpdatePagesService
return
unless
data
[
:build_name
]
==
'pages'
return
unless
data
[
:build_name
]
==
'pages'
return
unless
data
[
:build_status
]
==
'success'
return
unless
data
[
:build_status
]
==
'success'
PagesWorker
.
perform_async
(
data
[
:build_id
])
PagesWorker
.
perform_async
(
:deploy
,
data
[
:build_id
])
end
end
end
end
app/workers/pages_worker.rb
View file @
e9e8a2f6
...
@@ -7,7 +7,11 @@ class PagesWorker
...
@@ -7,7 +7,11 @@ class PagesWorker
sidekiq_options
queue: :pages
,
retry:
false
sidekiq_options
queue: :pages
,
retry:
false
def
perform
(
build_id
)
def
perform
(
action
,
*
arg
)
send
(
action
,
*
arg
)
end
def
deploy
(
build_id
)
@build_id
=
build_id
@build_id
=
build_id
return
unless
valid?
return
unless
valid?
...
@@ -36,6 +40,11 @@ class PagesWorker
...
@@ -36,6 +40,11 @@ class PagesWorker
return
false
return
false
end
end
def
remove
(
namespace_path
,
project_path
)
full_path
=
File
.
join
(
Settings
.
pages
.
path
,
namespace_path
,
project_path
)
FileUtils
.
rm_r
(
full_path
,
force:
true
)
end
private
private
def
create_status
def
create_status
...
...
spec/workers/pages_worker_spec.rb
View file @
e9e8a2f6
...
@@ -18,41 +18,48 @@ describe PagesWorker do
...
@@ -18,41 +18,48 @@ describe PagesWorker do
it
'succeeds'
do
it
'succeeds'
do
expect
(
project
.
pages_url
).
to
be_nil
expect
(
project
.
pages_url
).
to
be_nil
expect
(
worker
.
perform
(
build
.
id
)).
to
be_truthy
expect
(
worker
.
deploy
(
build
.
id
)).
to
be_truthy
expect
(
project
.
pages_url
).
to_not
be_nil
expect
(
project
.
pages_url
).
to_not
be_nil
end
end
it
'limits pages size'
do
it
'limits pages size'
do
stub_application_setting
(
max_pages_size:
1
)
stub_application_setting
(
max_pages_size:
1
)
expect
(
worker
.
perform
(
build
.
id
)).
to_not
be_truthy
expect
(
worker
.
deploy
(
build
.
id
)).
to_not
be_truthy
end
end
it
'removes pages after destroy'
do
it
'removes pages after destroy'
do
expect
(
PagesWorker
).
to
receive
(
:perform_in
)
expect
(
project
.
pages_url
).
to
be_nil
expect
(
project
.
pages_url
).
to
be_nil
expect
(
worker
.
perform
(
build
.
id
)).
to
be_truthy
expect
(
worker
.
deploy
(
build
.
id
)).
to
be_truthy
expect
(
project
.
pages_url
).
to_not
be_nil
expect
(
project
.
pages_url
).
to_not
be_nil
project
.
destroy
project
.
destroy
expect
(
Dir
.
exist?
(
project
.
public_pages_path
)).
to
be_falsey
expect
(
Dir
.
exist?
(
project
.
public_pages_path
)).
to
be_falsey
end
end
end
end
it
'fails to remove project pages when no pages is deployed'
do
expect
(
PagesWorker
).
to_not
receive
(
:perform_in
)
expect
(
project
.
pages_url
).
to
be_nil
project
.
destroy
end
it
'fails if no artifacts'
do
it
'fails if no artifacts'
do
expect
(
worker
.
perform
(
build
.
id
)).
to_not
be_truthy
expect
(
worker
.
deploy
(
build
.
id
)).
to_not
be_truthy
end
end
it
'fails for empty file fails'
do
it
'fails for empty file fails'
do
build
.
update_attributes
(
artifacts_file:
empty_file
)
build
.
update_attributes
(
artifacts_file:
empty_file
)
expect
(
worker
.
perform
(
build
.
id
)).
to_not
be_truthy
expect
(
worker
.
deploy
(
build
.
id
)).
to_not
be_truthy
end
end
it
'fails for invalid archive'
do
it
'fails for invalid archive'
do
build
.
update_attributes
(
artifacts_file:
invalid_file
)
build
.
update_attributes
(
artifacts_file:
invalid_file
)
expect
(
worker
.
perform
(
build
.
id
)).
to_not
be_truthy
expect
(
worker
.
deploy
(
build
.
id
)).
to_not
be_truthy
end
end
it
'fails if sha on branch is not latest'
do
it
'fails if sha on branch is not latest'
do
commit
.
update_attributes
(
sha:
'old_sha'
)
commit
.
update_attributes
(
sha:
'old_sha'
)
build
.
update_attributes
(
artifacts_file:
file
)
build
.
update_attributes
(
artifacts_file:
file
)
expect
(
worker
.
perform
(
build
.
id
)).
to_not
be_truthy
expect
(
worker
.
deploy
(
build
.
id
)).
to_not
be_truthy
end
end
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