Skip to content

Commit

Permalink
Correctly initializing uploaders after parsing flags (related to aero…
Browse files Browse the repository at this point in the history
  • Loading branch information
vania-pooh committed Nov 16, 2018
1 parent 257648e commit cc0fc73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/aerokube/selenoid/protect"
"github.com/aerokube/selenoid/service"
"github.com/aerokube/selenoid/session"
_ "github.com/aerokube/selenoid/upload"
"github.com/aerokube/selenoid/upload"
"github.com/aerokube/util"
"github.com/aerokube/util/docker"
"github.com/docker/docker/client"
Expand Down Expand Up @@ -174,6 +174,8 @@ func init() {
log.Printf("[-] [INIT] [Logs Dir: %s]", logOutputDir)
}

upload.Init()

environment := service.Environment{
InDocker: inDocker,
CPU: int64(cpu),
Expand Down
13 changes: 8 additions & 5 deletions upload/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/aerokube/selenoid/event"
"github.com/aerokube/util"
"log"
"sync"
"time"
)

Expand All @@ -18,17 +17,21 @@ type Uploader interface {

type Upload struct {
uploaders []Uploader
lock sync.Mutex
}

func Init() {
if upl != nil {
for _, upl := range upl.uploaders {
event.InitIfNeeded(upl)
}
}
}

func AddUploader(u Uploader) {
if upl == nil {
upl = &Upload{}
event.AddFileCreatedListener(upl)
}
upl.lock.Lock()
defer upl.lock.Unlock()
event.InitIfNeeded(u)
upl.uploaders = append(upl.uploaders, u)
}

Expand Down

0 comments on commit cc0fc73

Please sign in to comment.