Skip to content

Commit

Permalink
Merge pull request #455 from spiral/fix_reload_plugin
Browse files Browse the repository at this point in the history
plugin/reload fixes
  • Loading branch information
rustatian authored Dec 19, 2020
2 parents 73d3f96 + 52ac2c3 commit b8a8891
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 377 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ name: build
on:
push:
pull_request:
branches:
# Branches from forks have the form 'user:branch-name' so we only run
# this job on pull_request events for branches that look like fork
# branches. Without this we would end up running this job twice for non
# forked PRs, once for the push and then once for opening the PR.
- '**:**'

jobs:
php:
Expand Down
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
coverage:
status:
project:
default:
target: auto
threshold: 0%
informational: true
patch:
default:
target: auto
threshold: 0%
informational: true
7 changes: 4 additions & 3 deletions pipe_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package roadrunner

import (
"fmt"
"github.com/pkg/errors"
"github.com/spiral/goridge/v2"
"io"
"os/exec"

"github.com/pkg/errors"
"github.com/spiral/goridge/v2"
)

// PipeFactory connects to workers using standard
Expand Down Expand Up @@ -50,7 +51,7 @@ func (f *PipeFactory) SpawnWorker(cmd *exec.Cmd) (w *Worker, err error) {
err := w.Kill()
if err != nil {
// there is no logger here, how to handle error in goroutines ?
fmt.Println(fmt.Sprintf("error killing the worker with PID number %d, Created: %s", w.Pid, w.Created))
fmt.Printf("error killing the worker with PID number %d, Created: %s", w.Pid, w.Created)
}
}(w)

Expand Down
9 changes: 0 additions & 9 deletions service/reload/samefile.go

This file was deleted.

12 changes: 0 additions & 12 deletions service/reload/samefile_windows.go

This file was deleted.

35 changes: 18 additions & 17 deletions service/reload/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package reload

import (
"errors"
"github.com/sirupsen/logrus"
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/service"
"os"
"strings"
"time"

"github.com/sirupsen/logrus"
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/service"
)

// ID contains default service name.
Expand Down Expand Up @@ -51,20 +52,20 @@ func (s *Service) Init(cfg *Config, log *logrus.Logger, c service.Container) (bo
return false, err
}
configs = append(configs, WatcherConfig{
serviceName: serviceName,
recursive: config.Recursive,
directories: config.Dirs,
filterHooks: func(filename string, patterns []string) error {
ServiceName: serviceName,
Recursive: config.Recursive,
Directories: config.Dirs,
FilterHooks: func(filename string, patterns []string) error {
for i := 0; i < len(patterns); i++ {
if strings.Contains(filename, patterns[i]) {
return nil
}
}
return ErrorSkip
},
files: make(map[string]os.FileInfo),
ignored: ignored,
filePatterns: append(config.Patterns, cfg.Patterns...),
Files: make(map[string]os.FileInfo),
Ignored: ignored,
FilePatterns: append(config.Patterns, cfg.Patterns...),
})
}

Expand All @@ -91,7 +92,7 @@ func (s *Service) Serve() error {
}, 100)

// use the same interval
ticker := time.NewTicker(s.cfg.Interval)
timer := time.NewTimer(s.cfg.Interval)

// drain channel in case of leaved messages
defer func() {
Expand Down Expand Up @@ -120,15 +121,15 @@ func (s *Service) Serve() error {
case config := <-treshholdc:
// replace previous value in map by more recent without adding new one
updated[config.service] = config.serviceConfig
// stop ticker
ticker.Stop()
// stop timer
timer.Stop()
// restart
// logic is following:
// if we getting a lot of events, we should't restart particular service on each of it (user doing bug move or very fast typing)
// instead, we are resetting the ticker and wait for Interval time
// instead, we are resetting the timer and wait for Interval time
// If there is no more events, we restart service only once
ticker = time.NewTicker(s.cfg.Interval)
case <-ticker.C:
timer.Reset(s.cfg.Interval)
case <-timer.C:
if len(updated) > 0 {
for k, v := range updated {
sv := *v.service
Expand All @@ -142,7 +143,7 @@ func (s *Service) Serve() error {
updated = make(map[string]ServiceConfig, 100)
}
case <-s.stopc:
ticker.Stop()
timer.Stop()
return
}
}
Expand Down
1 change: 0 additions & 1 deletion service/reload/service_test.go

This file was deleted.

Loading

0 comments on commit b8a8891

Please sign in to comment.