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
a4ea9a93
Commit
a4ea9a93
authored
Feb 21, 2018
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ChroniDurationAttribute concern
parent
3c23cefa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
0 deletions
+56
-0
app/models/ci/runner.rb
app/models/ci/runner.rb
+3
-0
app/models/concerns/chronic_duration_attribute.rb
app/models/concerns/chronic_duration_attribute.rb
+25
-0
spec/models/concerns/chronic_duration_attribute_spec.rb
spec/models/concerns/chronic_duration_attribute_spec.rb
+28
-0
No files found.
app/models/ci/runner.rb
View file @
a4ea9a93
...
...
@@ -3,6 +3,7 @@ module Ci
extend
Gitlab
::
Ci
::
Model
include
Gitlab
::
SQL
::
Pattern
include
RedisCacheable
include
ChronicDurationAttribute
RUNNER_QUEUE_EXPIRY_TIME
=
60
.
minutes
ONLINE_CONTACT_TIMEOUT
=
1
.
hour
...
...
@@ -51,6 +52,8 @@ module Ci
cached_attr_reader
:version
,
:revision
,
:platform
,
:architecture
,
:contacted_at
,
:ip_address
chronic_duration_attribute
:job_upper_timeout_user_readable
,
:job_upper_timeout
# Searches for runners matching the given query.
#
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
...
...
app/models/concerns/chronic_duration_attribute.rb
0 → 100644
View file @
a4ea9a93
module
ChronicDurationAttribute
extend
ActiveSupport
::
Concern
class_methods
do
def
chronic_duration_attribute
(
virtual_attribute
,
source_attribute
)
chronic_duration_attribute_reader
(
virtual_attribute
,
source_attribute
)
chronic_duration_attribute_writer
(
virtual_attribute
,
source_attribute
)
end
def
chronic_duration_attribute_reader
(
virtual_attribute
,
source_attribute
)
define_method
(
virtual_attribute
)
do
value
=
self
.
send
(
source_attribute
)
# rubocop:disable GitlabSecurity/PublicSend
ChronicDuration
.
output
(
value
,
format: :short
)
unless
value
.
nil?
end
end
def
chronic_duration_attribute_writer
(
virtual_attribute
,
source_attribute
)
define_method
(
"
#{
virtual_attribute
}
="
)
do
|
value
|
new_value
=
ChronicDuration
.
parse
(
value
).
to_i
self
.
send
(
"
#{
source_attribute
}
="
,
new_value
)
# rubocop:disable GitlabSecurity/PublicSend
new_value
end
end
end
end
spec/models/concerns/chronic_duration_attribute_spec.rb
0 → 100644
View file @
a4ea9a93
require
'spec_helper'
shared_examples
'ChronicDurationAttribute'
do
describe
'dynamically defined methods'
do
it
{
expect
(
subject
.
class
).
to
be_public_method_defined
(
virtual_field
)
}
it
{
expect
(
subject
.
class
).
to
be_public_method_defined
(
"
#{
virtual_field
}
="
)
}
it
'parses chronic duration input'
do
subject
.
send
(
"
#{
virtual_field
}
="
,
"10m"
)
expect
(
subject
.
send
(
source_field
)).
to
eq
(
600
)
end
it
'outputs chronic duration formated value'
do
subject
.
send
(
"
#{
source_field
}
="
,
120
)
expect
(
subject
.
send
(
virtual_field
)).
to
eq
(
'2m'
)
end
end
end
describe
'ChronicDurationAttribute'
do
let
(
:source_field
)
{
:maximum_job_timeout
}
let
(
:virtual_field
)
{
:maximum_job_timeout_user_readable
}
subject
{
Ci
::
Runner
.
new
}
it_behaves_like
'ChronicDurationAttribute'
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