Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
b8b39edb
Commit
b8b39edb
authored
Sep 15, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't schedule updates for completed games
parent
b3c77b0a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
4 deletions
+28
-4
player.go
op-challenger/game/fault/player.go
+4
-0
coordinator.go
op-challenger/game/scheduler/coordinator.go
+11
-3
coordinator_test.go
op-challenger/game/scheduler/coordinator_test.go
+8
-1
types.go
op-challenger/game/scheduler/types.go
+1
-0
worker_test.go
op-challenger/game/scheduler/worker_test.go
+4
-0
No files found.
op-challenger/game/fault/player.go
View file @
b8b39edb
...
@@ -114,6 +114,10 @@ func NewGamePlayer(
...
@@ -114,6 +114,10 @@ func NewGamePlayer(
},
nil
},
nil
}
}
func
(
g
*
GamePlayer
)
Status
()
gameTypes
.
GameStatus
{
return
g
.
status
}
func
(
g
*
GamePlayer
)
ProgressGame
(
ctx
context
.
Context
)
gameTypes
.
GameStatus
{
func
(
g
*
GamePlayer
)
ProgressGame
(
ctx
context
.
Context
)
gameTypes
.
GameStatus
{
if
g
.
status
!=
gameTypes
.
GameStatusInProgress
{
if
g
.
status
!=
gameTypes
.
GameStatusInProgress
{
// Game is already complete so don't try to perform further actions.
// Game is already complete so don't try to perform further actions.
...
...
op-challenger/game/scheduler/coordinator.go
View file @
b8b39edb
...
@@ -64,8 +64,12 @@ func (c *coordinator) schedule(ctx context.Context, games []common.Address) erro
...
@@ -64,8 +64,12 @@ func (c *coordinator) schedule(ctx context.Context, games []common.Address) erro
if
j
,
err
:=
c
.
createJob
(
addr
);
err
!=
nil
{
if
j
,
err
:=
c
.
createJob
(
addr
);
err
!=
nil
{
errs
=
append
(
errs
,
err
)
errs
=
append
(
errs
,
err
)
}
else
if
j
!=
nil
{
}
else
if
j
!=
nil
{
jobs
=
append
(
jobs
,
*
j
)
if
j
.
status
==
types
.
GameStatusInProgress
{
c
.
m
.
RecordGameUpdateScheduled
()
jobs
=
append
(
jobs
,
*
j
)
c
.
m
.
RecordGameUpdateScheduled
()
}
else
{
c
.
logger
.
Warn
(
"Resolved game update not scheduled"
,
"game"
,
addr
,
"status"
,
j
.
status
)
}
}
}
state
,
ok
:=
c
.
states
[
addr
]
state
,
ok
:=
c
.
states
[
addr
]
if
ok
{
if
ok
{
...
@@ -93,6 +97,7 @@ func (c *coordinator) schedule(ctx context.Context, games []common.Address) erro
...
@@ -93,6 +97,7 @@ func (c *coordinator) schedule(ctx context.Context, games []common.Address) erro
// createJob updates the state for the specified game and returns the job to enqueue for it, if any
// createJob updates the state for the specified game and returns the job to enqueue for it, if any
// Returns (nil, nil) when there is no error and no job to enqueue
// Returns (nil, nil) when there is no error and no job to enqueue
func
(
c
*
coordinator
)
createJob
(
game
common
.
Address
)
(
*
job
,
error
)
{
func
(
c
*
coordinator
)
createJob
(
game
common
.
Address
)
(
*
job
,
error
)
{
j
:=
&
job
{
addr
:
game
}
state
,
ok
:=
c
.
states
[
game
]
state
,
ok
:=
c
.
states
[
game
]
if
!
ok
{
if
!
ok
{
state
=
&
gameState
{}
state
=
&
gameState
{}
...
@@ -109,9 +114,12 @@ func (c *coordinator) createJob(game common.Address) (*job, error) {
...
@@ -109,9 +114,12 @@ func (c *coordinator) createJob(game common.Address) (*job, error) {
return
nil
,
fmt
.
Errorf
(
"failed to create game player: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to create game player: %w"
,
err
)
}
}
state
.
player
=
player
state
.
player
=
player
state
.
status
=
player
.
Status
()
}
}
state
.
inflight
=
true
state
.
inflight
=
true
return
&
job
{
addr
:
game
,
player
:
state
.
player
},
nil
j
.
player
=
state
.
player
j
.
status
=
state
.
status
return
j
,
nil
}
}
func
(
c
*
coordinator
)
enqueueJob
(
ctx
context
.
Context
,
j
job
)
error
{
func
(
c
*
coordinator
)
enqueueJob
(
ctx
context
.
Context
,
j
job
)
error
{
...
...
op-challenger/game/scheduler/coordinator_test.go
View file @
b8b39edb
...
@@ -150,7 +150,10 @@ func TestDeleteDataForResolvedGames(t *testing.T) {
...
@@ -150,7 +150,10 @@ func TestDeleteDataForResolvedGames(t *testing.T) {
gameAddrs
:=
[]
common
.
Address
{
gameAddr1
,
gameAddr2
,
gameAddr3
}
gameAddrs
:=
[]
common
.
Address
{
gameAddr1
,
gameAddr2
,
gameAddr3
}
require
.
NoError
(
t
,
c
.
schedule
(
ctx
,
gameAddrs
))
require
.
NoError
(
t
,
c
.
schedule
(
ctx
,
gameAddrs
))
require
.
Len
(
t
,
workQueue
,
len
(
gameAddrs
),
"should schedule all games"
)
// The work queue should only contain jobs for games 1 and 2
// A resolved game should not be scheduled for an update.
// This makes the inflight game metric more robust.
require
.
Len
(
t
,
workQueue
,
2
,
"should schedule all games"
)
// Game 1 progresses and is still in progress
// Game 1 progresses and is still in progress
// Game 2 progresses and is now resolved
// Game 2 progresses and is now resolved
...
@@ -249,6 +252,10 @@ func (g *stubGame) ProgressGame(_ context.Context) types.GameStatus {
...
@@ -249,6 +252,10 @@ func (g *stubGame) ProgressGame(_ context.Context) types.GameStatus {
return
g
.
status
return
g
.
status
}
}
func
(
g
*
stubGame
)
Status
()
types
.
GameStatus
{
return
g
.
status
}
type
createdGames
struct
{
type
createdGames
struct
{
t
*
testing
.
T
t
*
testing
.
T
createCompleted
common
.
Address
createCompleted
common
.
Address
...
...
op-challenger/game/scheduler/types.go
View file @
b8b39edb
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
type
GamePlayer
interface
{
type
GamePlayer
interface
{
ProgressGame
(
ctx
context
.
Context
)
types
.
GameStatus
ProgressGame
(
ctx
context
.
Context
)
types
.
GameStatus
Status
()
types
.
GameStatus
}
}
type
DiskManager
interface
{
type
DiskManager
interface
{
...
...
op-challenger/game/scheduler/worker_test.go
View file @
b8b39edb
...
@@ -47,6 +47,10 @@ func (s *stubPlayer) ProgressGame(ctx context.Context) types.GameStatus {
...
@@ -47,6 +47,10 @@ func (s *stubPlayer) ProgressGame(ctx context.Context) types.GameStatus {
return
s
.
status
return
s
.
status
}
}
func
(
s
*
stubPlayer
)
Status
()
types
.
GameStatus
{
return
s
.
status
}
func
readWithTimeout
[
T
any
](
t
*
testing
.
T
,
ch
<-
chan
T
)
T
{
func
readWithTimeout
[
T
any
](
t
*
testing
.
T
,
ch
<-
chan
T
)
T
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
...
...
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