-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to memory db #5
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like where this is going, looks good for most of it. Missing the crucial StartTask
part but that's it. Good work!
internal/docker-client/docker.go
Outdated
"github.com/Capstone-auto-grader/grader-api-v2/internal/grader-task" | ||
"github.com/Capstone-auto-grader/grader-api-v2/internal/graderd" | ||
"github.com/Capstone-auto-grader/grader-api-v2/internal/sync-map" | ||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/client" | ||
"io/ioutil" | ||
"log" | ||
|
||
"github.com/pkg/errors" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to organize packages as groups: https://github.com/golang/go/wiki/CodeReviewComments#imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ same for other files as well
cmd/graderd/main.go
Outdated
"github.com/Capstone-auto-grader/grader-api-v2/internal/docker-client" | ||
sync_map "github.com/Capstone-auto-grader/grader-api-v2/internal/sync-map" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use single word names: https://golang.org/doc/effective_go.html#package-names
cmd/graderd/main.go
Outdated
@@ -54,7 +56,7 @@ func serve() error { | |||
log.Fatalln(errors.Wrap(err, failedCertCreation)) | |||
} | |||
grpcServer := grpc.NewServer(grpc.Creds(serverCert)) | |||
graderService := graderd.NewGraderService(graderd.NewDockerClient(*dockerAddr, *dockerVersion), graderd.NewPGDatabase(*databaseAddr), *webAddr) | |||
graderService := graderd.NewGraderService(docker_client.NewDockerClient(*dockerAddr, *dockerVersion, sync_map.NewSyncMap(), 2), *webAddr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about creating and passing the sync_map
in the constructor of docker_client
, any reason why we don't just create it inside the constructor?
_ = tasks.UpdateStatus(taskId, grader_task.StatusStarted, true) | ||
_ = client.StartTask(context.Background(), taskId) | ||
_,_ = client.TaskOutput(context.Background(), taskId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can make another channel here for propagating errors out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking a channel for all responses and errors, so another worker can deal with them
internal/docker-client/docker.go
Outdated
for _, t := range tasks { | ||
if t.ContainerID == c.ID { | ||
status := graderd.ParseContainerState(c.State) | ||
if status == grader_task.StatusStarted { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we show the tasks that stopped unexpectedly as well, just a thought.
"sync" | ||
"github.com/Capstone-auto-grader/grader-api-v2/internal/grader-task" | ||
) | ||
// A synchronized map to store Tasks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment should start with "SyncMap is ..."/"SyncMap ... ": https://golang.org/doc/effective_go.html#commentary
internal/docker-client/docker.go
Outdated
type DockerClient struct { | ||
cli *client.Client | ||
mp *sync_map.SyncMap | ||
queue chan<- string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this two-way, otherwise you won't be able to pass stuff in.
//} | ||
|
||
func (d *DockerClient) StartTask(ctx context.Context, taskID string) error { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the important part is missing!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hammering that one out after I write the rest of it!
internal/sync-map/map.go
Outdated
defer m.mu.Unlock() | ||
t := m.mp[taskID] | ||
if checkStatus && t.Status == grader_task.StatusStarted { | ||
return fmt.Errorf("task already started") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use errors.New(...)
instead
return nil | ||
} | ||
|
||
func (m *SyncMap) Enumerate() map[string]grader_task.Task { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not very sure about this approach. Can you explain more on why we need to copy the whole map everytime? When the use-case is just readonly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried about a concurrent update to some of the elements of the task (status or containerID) in the middle of reading. Thinking about it more, I don't think it would be the worst thing in the world to have an intermediate state read, what do you think @xumr0x ?
No description provided.