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
e2aff3de
Commit
e2aff3de
authored
Jan 05, 2018
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create JobArtifactDeletedEvent on destroy artifact
parent
b7dd9dec
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
142 additions
and
1 deletion
+142
-1
ee/app/models/ee/ci/job_artifact.rb
ee/app/models/ee/ci/job_artifact.rb
+12
-0
ee/app/models/geo/job_artifact_deleted_event.rb
ee/app/models/geo/job_artifact_deleted_event.rb
+1
-1
ee/app/services/geo/job_artifact_deleted_event_store.rb
ee/app/services/geo/job_artifact_deleted_event_store.rb
+48
-0
spec/ee/spec/models/ee/ci/job_artifact_spec.rb
spec/ee/spec/models/ee/ci/job_artifact_spec.rb
+16
-0
spec/ee/spec/services/geo/job_artifact_deleted_event_store_spec.rb
...pec/services/geo/job_artifact_deleted_event_store_spec.rb
+65
-0
No files found.
ee/app/models/ee/ci/job_artifact.rb
View file @
e2aff3de
...
...
@@ -7,7 +7,19 @@ module EE
extend
ActiveSupport
::
Concern
prepended
do
after_destroy
:log_geo_event
scope
:with_files_stored_locally
,
->
{
where
(
file_store:
[
nil
,
JobArtifactUploader
::
LOCAL_STORE
])
}
end
def
local_store?
[
nil
,
JobArtifactUploader
::
LOCAL_STORE
].
include?
(
self
.
file_store
)
end
private
def
log_geo_event
::
Geo
::
JobArtifactDeletedEventStore
.
new
(
self
).
create
end
end
end
ee/app/models/geo/job_artifact_deleted_event.rb
View file @
e2aff3de
...
...
@@ -4,6 +4,6 @@ module Geo
belongs_to
:job_artifact
,
class_name:
'Ci::JobArtifact'
validates
:job_artifact
,
presence:
true
validates
:job_artifact
,
:file_path
,
presence:
true
end
end
ee/app/services/geo/job_artifact_deleted_event_store.rb
0 → 100644
View file @
e2aff3de
module
Geo
class
JobArtifactDeletedEventStore
<
EventStore
self
.
event_type
=
:job_artifact_deleted_event
attr_reader
:job_artifact
def
initialize
(
job_artifact
)
@job_artifact
=
job_artifact
end
def
create
return
unless
job_artifact
.
local_store?
super
end
private
def
build_event
Geo
::
JobArtifactDeletedEvent
.
new
(
job_artifact:
job_artifact
,
file_path:
relative_file_path
)
end
def
local_store_path
Pathname
.
new
(
JobArtifactUploader
.
local_store_path
)
end
def
relative_file_path
return
unless
job_artifact
.
file
.
present?
Pathname
.
new
(
job_artifact
.
file
.
path
).
relative_path_from
(
local_store_path
)
end
# This is called by ProjectLogHelpers to build json log with context info
#
# @see ::Gitlab::Geo::ProjectLogHelpers
def
base_log_data
(
message
)
{
class:
self
.
class
.
name
,
job_artifact_id:
job_artifact
.
id
,
file_path:
job_artifact
.
file
.
path
,
message:
message
}
end
end
end
spec/ee/spec/models/ee/ci/job_artifact_spec.rb
0 → 100644
View file @
e2aff3de
require
'spec_helper'
describe
EE
::
Ci
::
JobArtifact
do
describe
'#destroy'
do
set
(
:primary
)
{
create
(
:geo_node
,
:primary
)
}
set
(
:secondary
)
{
create
(
:geo_node
)
}
it
'creates a JobArtifactDeletedEvent'
do
job_artifact
=
create
(
:ci_job_artifact
,
:archive
)
expect
do
job_artifact
.
destroy
end
.
to
change
{
Geo
::
JobArtifactDeletedEvent
.
count
}.
by
(
1
)
end
end
end
spec/ee/spec/services/geo/job_artifact_deleted_event_store_spec.rb
0 → 100644
View file @
e2aff3de
require
'spec_helper'
describe
Geo
::
JobArtifactDeletedEventStore
do
set
(
:secondary_node
)
{
create
(
:geo_node
)
}
let
(
:job_artifact
)
{
create
(
:ci_job_artifact
,
:archive
)
}
subject
(
:event_store
)
{
described_class
.
new
(
job_artifact
)
}
describe
'#create'
do
it
'does not create an event when not running on a primary node'
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
false
}
expect
{
event_store
.
create
}.
not_to
change
(
Geo
::
JobArtifactDeletedEvent
,
:count
)
end
context
'when running on a primary node'
do
before
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
true
}
end
it
'does not create an event when LFS object is not on a local store'
do
allow
(
job_artifact
).
to
receive
(
:local_store?
).
and_return
(
false
)
expect
{
event_store
.
create
}.
not_to
change
(
Geo
::
JobArtifactDeletedEvent
,
:count
)
end
it
'does not create an event when there are no secondary nodes'
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:secondary_nodes
)
{
[]
}
expect
{
event_store
.
create
}.
not_to
change
(
Geo
::
JobArtifactDeletedEvent
,
:count
)
end
it
'creates a LFS object deleted event'
do
expect
{
event_store
.
create
}.
to
change
(
Geo
::
JobArtifactDeletedEvent
,
:count
).
by
(
1
)
end
it
'tracks LFS object attributes'
do
event_store
.
create
event
=
Geo
::
JobArtifactDeletedEvent
.
last
expect
(
event
.
job_artifact_id
).
to
eq
(
job_artifact
.
id
)
expect
(
event
.
file_path
).
to
match
(
%r{
\A\h
+/
\h
+/
\h
+/[
\d
_]+/
\d
+/
\d
+/ci_build_artifacts.zip
\z
}
)
end
it
'logs an error message when event creation fail'
do
invalid_job_artifact
=
create
(
:ci_job_artifact
)
event_store
=
described_class
.
new
(
invalid_job_artifact
)
expected_message
=
{
class:
"Geo::JobArtifactDeletedEventStore"
,
job_artifact_id:
invalid_job_artifact
.
id
,
file_path:
nil
,
message:
"Job artifact deleted event could not be created"
,
error:
"Validation failed: File path can't be blank"
}
expect
(
Gitlab
::
Geo
::
Logger
).
to
receive
(
:error
)
.
with
(
expected_message
).
and_call_original
event_store
.
create
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