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
1becbca3
Commit
1becbca3
authored
Apr 06, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract an abstract class FileService
parent
317a6ada
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
46 deletions
+40
-46
app/services/geo/file_download_service.rb
app/services/geo/file_download_service.rb
+2
-25
app/services/geo/file_service.rb
app/services/geo/file_service.rb
+34
-0
app/services/geo/file_upload_service.rb
app/services/geo/file_upload_service.rb
+4
-21
No files found.
app/services/geo/file_download_service.rb
View file @
1becbca3
module
Geo
class
FileDownloadService
attr_reader
:object_type
,
:object_db_id
class
FileDownloadService
<
FileService
LEASE_TIMEOUT
=
8
.
hours
.
freeze
DEFAULT_OBJECT_TYPES
=
%w[attachment avatar file]
.
freeze
def
initialize
(
object_type
,
object_db_id
)
@object_type
=
object_type
.
to_s
@object_db_id
=
object_db_id
end
def
execute
try_obtain_lease
do
|
lease
|
...
...
@@ -21,24 +13,13 @@ module Geo
private
def
downloader
klass
=
downloader_klass_name
.
constantize
klass
=
"Gitlab::Geo::
#{
service_klass_name
}
Downloader"
.
constantize
klass
.
new
(
object_type
,
object_db_id
)
rescue
NameError
log
(
"Unknown file type:
#{
object_type
}
"
)
raise
end
def
downloader_klass_name
klass_name
=
if
DEFAULT_OBJECT_TYPES
.
include?
(
object_type
)
'file'
else
object_type
end
"Gitlab::Geo::
#{
klass_name
.
camelize
}
Downloader"
end
def
try_obtain_lease
uuid
=
Gitlab
::
ExclusiveLease
.
new
(
lease_key
,
timeout:
LEASE_TIMEOUT
).
try_obtain
...
...
@@ -64,9 +45,5 @@ module Geo
def
lease_key
"file_download_service:
#{
object_type
}
:
#{
object_db_id
}
"
end
def
log
(
message
)
Rails
.
logger
.
info
"
#{
self
.
class
.
name
}
:
#{
message
}
"
end
end
end
app/services/geo/file_service.rb
0 → 100644
View file @
1becbca3
module
Geo
class
FileService
attr_reader
:object_type
,
:object_db_id
DEFAULT_OBJECT_TYPES
=
%w[attachment avatar file]
.
freeze
DEFAULT_SERVICE_TYPE
=
'file'
.
freeze
def
initialize
(
object_type
,
object_db_id
)
@object_type
=
object_type
.
to_s
@object_db_id
=
object_db_id
end
def
execute
raise
NotImplementedError
end
private
def
service_klass_name
klass_name
=
if
DEFAULT_OBJECT_TYPES
.
include?
(
object_type
)
DEFAULT_SERVICE_TYPE
else
object_type
end
klass_name
.
camelize
end
def
log
(
message
)
Rails
.
logger
.
info
"
#{
self
.
class
.
name
}
:
#{
message
}
"
end
end
end
app/services/geo/file_upload_service.rb
View file @
1becbca3
module
Geo
class
FileUploadService
DEFAULT_OBJECT_TYPES
=
%w[attachment avatar file]
.
freeze
class
FileUploadService
<
FileService
IAT_LEEWAY
=
60
.
seconds
.
to_i
attr_reader
:
object_type
,
:object_db_id
,
:
auth_header
attr_reader
:auth_header
def
initialize
(
params
,
auth_header
)
@object_type
=
params
[
:type
]
@object_db_id
=
params
[
:id
]
super
(
params
[
:type
],
params
[
:id
])
@auth_header
=
auth_header
end
...
...
@@ -22,25 +20,10 @@ module Geo
private
def
uploader_klass
uploader_klass_name
.
constantize
"Gitlab::Geo::
#{
service_klass_name
}
Uploader"
.
constantize
rescue
NameError
log
(
"Unknown file type:
#{
object_type
}
"
)
raise
end
def
uploader_klass_name
klass_name
=
if
DEFAULT_OBJECT_TYPES
.
include?
(
object_type
)
'file'
else
object_type
end
"Gitlab::Geo::
#{
klass_name
.
camelize
}
Uploader"
end
def
log
(
message
)
Rails
.
logger
.
info
"
#{
self
.
class
.
name
}
:
#{
message
}
"
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