Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
projects.thm.de
GitLab
Commits
1f898f1e
Unverified
Commit
1f898f1e
authored
May 08, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update commit status from external CI services less aggressively
parent
0eb74426
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
14 deletions
+30
-14
app/models/concerns/reactive_caching.rb
app/models/concerns/reactive_caching.rb
+10
-7
changelogs/unreleased/fix-reactive-cache-retry-rate.yml
changelogs/unreleased/fix-reactive-cache-retry-rate.yml
+5
-0
spec/models/concerns/reactive_caching_spec.rb
spec/models/concerns/reactive_caching_spec.rb
+15
-7
No files found.
app/models/concerns/reactive_caching.rb
View file @
1f898f1e
...
...
@@ -60,13 +60,16 @@ def calculate_reactive_cache(*args)
end
def
with_reactive_cache
(
*
args
,
&
blk
)
within_reactive_cache_lifetime
(
*
args
)
do
bootstrap
=
!
within_reactive_cache_lifetime?
(
*
args
)
Rails
.
cache
.
write
(
alive_reactive_cache_key
(
*
args
),
true
,
expires_in:
self
.
class
.
reactive_cache_lifetime
)
if
bootstrap
ReactiveCachingWorker
.
perform_async
(
self
.
class
,
id
,
*
args
)
nil
else
data
=
Rails
.
cache
.
read
(
full_reactive_cache_key
(
*
args
))
yield
data
if
data
.
present?
end
ensure
Rails
.
cache
.
write
(
alive_reactive_cache_key
(
*
args
),
true
,
expires_in:
self
.
class
.
reactive_cache_lifetime
)
ReactiveCachingWorker
.
perform_async
(
self
.
class
,
id
,
*
args
)
end
def
clear_reactive_cache!
(
*
args
)
...
...
@@ -75,7 +78,7 @@ def clear_reactive_cache!(*args)
def
exclusively_update_reactive_cache!
(
*
args
)
locking_reactive_cache
(
*
args
)
do
within_reactive_cache_lifetime
(
*
args
)
do
if
within_reactive_cache_lifetime
?
(
*
args
)
enqueuing_update
(
*
args
)
do
value
=
calculate_reactive_cache
(
*
args
)
Rails
.
cache
.
write
(
full_reactive_cache_key
(
*
args
),
value
)
...
...
@@ -105,8 +108,8 @@ def locking_reactive_cache(*args)
Gitlab
::
ExclusiveLease
.
cancel
(
full_reactive_cache_key
(
*
args
),
uuid
)
end
def
within_reactive_cache_lifetime
(
*
args
)
yield
if
Rails
.
cache
.
read
(
alive_reactive_cache_key
(
*
args
))
def
within_reactive_cache_lifetime
?
(
*
args
)
!!
Rails
.
cache
.
read
(
alive_reactive_cache_key
(
*
args
))
end
def
enqueuing_update
(
*
args
)
...
...
changelogs/unreleased/fix-reactive-cache-retry-rate.yml
0 → 100644
View file @
1f898f1e
---
title
:
Update commit status from external CI services less aggressively
merge_request
:
18802
author
:
type
:
fixed
spec/models/concerns/reactive_caching_spec.rb
View file @
1f898f1e
...
...
@@ -29,12 +29,6 @@ def result
end
end
let
(
:now
)
{
Time
.
now
.
utc
}
around
do
|
example
|
Timecop
.
freeze
(
now
)
{
example
.
run
}
end
let
(
:calculation
)
{
->
{
2
+
2
}
}
let
(
:cache_key
)
{
"foo:666"
}
let
(
:instance
)
{
CacheTest
.
new
(
666
,
&
calculation
)
}
...
...
@@ -49,13 +43,15 @@ def result
context
'when cache is empty'
do
it
{
is_expected
.
to
be_nil
}
it
'queues a background worker'
do
it
'
en
queues a background worker
to bootstrap the cache
'
do
expect
(
ReactiveCachingWorker
).
to
receive
(
:perform_async
).
with
(
CacheTest
,
666
)
go!
end
it
'updates the cache lifespan'
do
expect
(
reactive_cache_alive?
(
instance
)).
to
be_falsy
go!
expect
(
reactive_cache_alive?
(
instance
)).
to
be_truthy
...
...
@@ -69,6 +65,18 @@ def result
it
{
is_expected
.
to
eq
(
2
)
}
it
'does not enqueue a background worker'
do
expect
(
ReactiveCachingWorker
).
not_to
receive
(
:perform_async
)
go!
end
it
'updates the cache lifespan'
do
expect
(
Rails
.
cache
).
to
receive
(
:write
).
with
(
alive_reactive_cache_key
(
instance
),
true
,
expires_in:
anything
)
go!
end
context
'and expired'
do
before
do
invalidate_reactive_cache
(
instance
)
...
...
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