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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
1f898f1e
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 @@ module ReactiveCaching
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 @@ module ReactiveCaching
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 @@ module ReactiveCaching
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 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
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 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
context
'when cache is empty'
do
it
{
is_expected
.
to
be_nil
}
it
'
queues a background worker
'
do
it
'
enqueues 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 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
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