Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Application Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
20
Issues
20
List
Boards
Labels
Service Desk
Milestones
Merge Requests
4
Merge Requests
4
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ganggo
Application Server
Commits
4cbfe567
Commit
4cbfe567
authored
Oct 26, 2018
by
zauberstuhl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit test for RetryOnFail
parent
fdb8eb73
Pipeline
#572
passed with stages
in 10 minutes and 54 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
77 additions
and
22 deletions
+77
-22
app/jobs/dispatch_comment.go
app/jobs/dispatch_comment.go
+1
-1
app/jobs/dispatch_contact.go
app/jobs/dispatch_contact.go
+1
-1
app/jobs/dispatch_like.go
app/jobs/dispatch_like.go
+1
-1
app/jobs/dispatch_post.go
app/jobs/dispatch_post.go
+1
-1
app/jobs/relay_comment.go
app/jobs/relay_comment.go
+2
-2
app/jobs/relay_like.go
app/jobs/relay_like.go
+1
-1
app/jobs/relay_retraction.go
app/jobs/relay_retraction.go
+1
-1
app/jobs/retry_on_fail.go
app/jobs/retry_on_fail.go
+23
-14
tests/jobstest.go
tests/jobstest.go
+46
-0
No files found.
app/jobs/dispatch_comment.go
View file @
4cbfe567
...
...
@@ -96,7 +96,7 @@ func (dispatcher *Dispatcher) Comment(comment models.Comment) {
}
// send and retry if it fails the first time
run
.
Now
(
Retry
{
run
.
Now
(
Retry
OnFail
{
Pod
:
&
person
.
Pod
,
Send
:
func
()
error
{
return
entity
.
Send
(
endpoint
,
priv
,
pub
)
...
...
app/jobs/dispatch_contact.go
View file @
4cbfe567
...
...
@@ -59,7 +59,7 @@ func (dispatcher *Dispatcher) Contact(contact models.AspectMembership) {
entity
.
SetSharing
(
true
)
// send and retry if it fails the first time
run
.
Now
(
Retry
{
run
.
Now
(
Retry
OnFail
{
Pod
:
&
person
.
Pod
,
Send
:
func
()
error
{
return
entity
.
Send
(
endpoint
,
priv
,
pub
)
...
...
app/jobs/dispatch_like.go
View file @
4cbfe567
...
...
@@ -87,7 +87,7 @@ func (dispatcher *Dispatcher) Like(like models.Like) {
}
// send and retry if it fails the first time
run
.
Now
(
Retry
{
run
.
Now
(
Retry
OnFail
{
Pod
:
&
person
.
Pod
,
Send
:
func
()
error
{
return
entity
.
Send
(
endpoint
,
priv
,
pub
)
...
...
app/jobs/dispatch_post.go
View file @
4cbfe567
...
...
@@ -110,7 +110,7 @@ func (dispatcher *Dispatcher) StatusMessage(post models.Post) {
}
// send and retry if it fails the first time
run
.
Now
(
Retry
{
run
.
Now
(
Retry
OnFail
{
Pod
:
&
person
.
Pod
,
Send
:
func
()
error
{
return
entity
.
Send
(
endpoint
,
priv
,
pub
)
...
...
app/jobs/relay_comment.go
View file @
4cbfe567
...
...
@@ -118,7 +118,7 @@ func (dispatcher *Dispatcher) RelayComment(entity federation.MessageComment) {
continue
}
// send and retry if it fails the first time
run
.
Now
(
Retry
{
run
.
Now
(
Retry
OnFail
{
Pod
:
&
person
.
Pod
,
Send
:
func
()
error
{
return
translate
.
Send
(
endpoint
,
priv
,
pub
)
...
...
@@ -129,7 +129,7 @@ func (dispatcher *Dispatcher) RelayComment(entity federation.MessageComment) {
entity
.
SetAuthor
(
parentUser
.
Person
.
Author
)
// send and retry if it fails the first time
run
.
Now
(
Retry
{
run
.
Now
(
Retry
OnFail
{
Pod
:
&
person
.
Pod
,
Send
:
func
()
error
{
return
entity
.
Send
(
endpoint
,
priv
,
pub
)
...
...
app/jobs/relay_like.go
View file @
4cbfe567
...
...
@@ -72,7 +72,7 @@ func (dispatcher *Dispatcher) RelayLike(entity federation.MessageLike) {
entity
.
SetAuthor
(
parentUser
.
Person
.
Author
)
// send and retry if it fails the first time
run
.
Now
(
Retry
{
run
.
Now
(
Retry
OnFail
{
Pod
:
&
person
.
Pod
,
Send
:
func
()
error
{
return
entity
.
Send
(
endpoint
,
priv
,
pub
)
...
...
app/jobs/relay_retraction.go
View file @
4cbfe567
...
...
@@ -132,7 +132,7 @@ func (dispatcher *Dispatcher) RelayRetraction(entity federation.MessageRetract)
}
// send and retry if it fails the first time
run
.
Now
(
Retry
{
run
.
Now
(
Retry
OnFail
{
Pod
:
&
person
.
Pod
,
Send
:
func
()
error
{
return
entity
.
Send
(
endpoint
,
priv
,
pub
)
...
...
app/jobs/retry.go
→
app/jobs/retry
_on_fail
.go
View file @
4cbfe567
...
...
@@ -24,21 +24,35 @@ import (
"time"
)
type
Retry
struct
{
type
Retry
OnFail
struct
{
Pod
*
models
.
Pod
Send
func
()
error
wait
time
.
Duration
After
[]
time
.
Duration
firstRun
bool
}
func
(
retry
Retry
)
Run
()
{
func
(
retry
RetryOnFail
)
Run
()
{
// set default values on first run
if
!
retry
.
firstRun
{
retry
.
firstRun
=
true
if
len
(
retry
.
After
)
==
0
{
retry
.
After
=
append
(
retry
.
After
,
[]
time
.
Duration
{
time
.
Minute
,
time
.
Hour
,
24
*
time
.
Hour
,
}
...
)
}
}
// execute job and check on errors
err
:=
retry
.
Send
()
if
err
!=
nil
{
if
retry
.
wait
==
0
{
retry
.
wait
=
time
.
Minute
}
else
if
retry
.
wait
==
time
.
Minute
{
retry
.
wait
=
time
.
Hour
}
else
if
retry
.
wait
==
time
.
Hour
{
retry
.
wait
=
24
*
time
.
Hour
if
len
(
retry
.
After
)
>
0
{
// repeat until timeout (empty array)
duration
:=
retry
.
After
[
0
]
retry
.
After
=
retry
.
After
[
1
:
]
// repeat until timeout (empty array)
revel
.
AppLog
.
Warn
(
"Jobs Retry"
,
"waitfor"
,
duration
,
"error"
,
err
)
run
.
In
(
duration
,
retry
)
}
else
{
// this server is probably down. skip it..
revel
.
AppLog
.
Error
(
"Jobs Retry"
,
"error"
,
err
)
...
...
@@ -49,11 +63,6 @@ func (retry Retry) Run() {
revel
.
AppLog
.
Error
(
"Jobs Retry"
,
"error"
,
err
)
}
}
return
}
revel
.
AppLog
.
Warn
(
"Jobs Retry"
,
"waitfor"
,
retry
.
wait
,
"error"
,
err
)
// repeat until timeout
run
.
In
(
retry
.
wait
,
retry
)
}
}
tests/jobstest.go
View file @
4cbfe567
...
...
@@ -23,6 +23,7 @@ import (
"git.feneas.org/ganggo/ganggo/app/models"
"git.feneas.org/ganggo/gorm"
"time"
"errors"
)
type
JobsTest
struct
{
...
...
@@ -137,3 +138,48 @@ func (t *JobsTest) TestTelegramReceiver() {
t
.
Assertf
(
len
(
tgReceiverTests
)
==
4
,
"Expected four entries, got %d"
,
len
(
tgReceiverTests
))
}
func
(
t
*
JobsTest
)
TestRetryOnFail
()
{
tests
:=
[]
struct
{
After
[]
time
.
Duration
Expected
int
}{
{
After
:
[]
time
.
Duration
{
time
.
Second
,
time
.
Second
,
time
.
Second
,
},
Expected
:
3
,
},
{
After
:
[]
time
.
Duration
{
time
.
Second
,
time
.
Second
,
},
Expected
:
2
,
},
{
After
:
[]
time
.
Duration
{
time
.
Second
,
time
.
Second
,
time
.
Second
,
time
.
Second
,
},
Expected
:
4
,
},
}
for
i
,
test
:=
range
tests
{
var
triggered
int
=
0
retry
:=
jobs
.
RetryOnFail
{
Send
:
func
()
error
{
triggered
+=
1
return
errors
.
New
(
"testing RetryOnFail"
)
},
After
:
test
.
After
,
}
retry
.
Run
()
// wait for async task
duration
:=
time
.
Duration
(
test
.
Expected
)
*
time
.
Second
time
.
Sleep
(
duration
)
t
.
Assertf
(
triggered
==
test
.
Expected
,
"#%d: Expected %d tries, got %d"
,
i
,
test
.
Expected
,
triggered
)
}
}
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