Skip to content
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

Allow to decide which tasks are going to be executed per playground #218

Merged
merged 1 commit into from
Nov 21, 2017

Conversation

xetorthio
Copy link
Contributor

@@ -52,7 +52,7 @@ func main() {
log.Fatalf("Cannot parse duration %s. Got: %v", config.DefaultSessionDuration, err)
}

playground := types.Playground{Domain: config.PlaygroundDomain, DefaultDinDInstanceImage: config.DefaultDinDImage, AllowWindowsInstances: config.NoWindows, DefaultSessionDuration: d, AvailableDinDInstanceImages: []string{config.DefaultDinDImage}}
playground := types.Playground{Domain: config.PlaygroundDomain, DefaultDinDInstanceImage: config.DefaultDinDImage, AllowWindowsInstances: config.NoWindows, DefaultSessionDuration: d, AvailableDinDInstanceImages: []string{config.DefaultDinDImage}, Tasks: []string{".*"}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we say that the default should be "don't run any tasks unless specified" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default of the Playground struct is an empty string slice, which means don't run anything. But when you run the playground locally (for development for example) you want the scheduler to do something, right? Like show the ports that you open, etc. Do you prefer it not to show anything and change the current behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if the config will be retrieved from the DB shoudn't we populate the local db with that config instead of hardcoding it in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you populate the DB with the playground for development if you don't do it here?


storage storage.StorageApi
event event.EventApi
pwd pwd.PWDApi
mx sync.Mutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what I see in the a PR, a single scheduler can handle multiple plagrounds, so shouldn't this mutex be per-playground?. The way it's implemented, every time it's used it'll hold on all the playgrounds operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you going to do it? This is to update the managed playgrounds and matched tasks. Send away your suggestions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a mutex per playground instead one mutex for all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And how do you update the playground list in a way that is safe?

func (s *scheduler) schedulePlaygroundsUpdate() {
s.updatePlaygrounds()
s.ticker = time.NewTicker(time.Minute * 5)
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

running the update in a goroutine doesn't make too much sense as they will get executed sequentially because of the mutex. right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand. The idea is that the schedulePlaygroundUpdate returns and doesn't block forever.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, my bad.

matchedTasks = append(matchedTasks, task)
continue
}
matched, err := regexp.MatchString(expr, task.Name())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will compile the regex every time. Shouldn't we make expr a *Regexp and compile them when updating the playground config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Good idea. I will change it!

}

func (s *scheduler) getTasks(playgroundId string) []Task {
s.mx.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're blocking everything (all the playgrounds) just to retrieve the tasks for only one playground. I'm aware that this should be extremely fast.. but still IDK if it's the best approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are more than welcome to propose a better approach :) As long as it is simple.

log.Printf("EVENT: Session New %s\n", sessionId)
session, err := s.storage.SessionGet(sessionId)
if err != nil {
log.Printf("Session [%s] was not found in storage. Got %s\n", sessionId, err)
return
}
if _, found := s.playgrounds[session.PlaygroundId]; !found {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do this here also?. Isn't this be populated here: https://github.com/play-with-docker/play-with-docker/pull/218/files#diff-9667cfa1ad6b8b445794f7c2469f069fR244 before in Start function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We populate on Start for all sessions we retrieve from the DB. But then new sessions could be created, on different playgrounds, so we need to populate for the new playgrounds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

@marcosnils marcosnils merged commit 95e4aaa into master Nov 21, 2017
@marcosnils marcosnils deleted the tasks_per_playground branch November 21, 2017 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants