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

Share HTML template renderers and create a watcher framework #20218

Merged
merged 28 commits into from
Aug 28, 2022
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1409281
Share HTML template renderers and create a watcher framework
zeripath Jun 28, 2022
07dc4f2
placate lint
zeripath Jul 3, 2022
f265ce5
fix windows
zeripath Jul 3, 2022
726bf7c
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 4, 2022
aa90128
Init needs a ctx
zeripath Jul 4, 2022
0209fa4
make SSPI also share the templates too
zeripath Jul 4, 2022
a04e94a
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 5, 2022
7dd067b
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 6, 2022
f61f79c
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 9, 2022
cbdc8bc
use todo only
zeripath Jul 10, 2022
9e63150
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 12, 2022
1159e0f
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 12, 2022
959595b
Switch to use syncthing/notify instead of fsnotify/fsnotify
zeripath Jul 16, 2022
aca2416
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Jul 16, 2022
426eb8f
Revert "Switch to use syncthing/notify instead of fsnotify/fsnotify"
zeripath Jul 17, 2022
f3b8468
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 31, 2022
eb8cf0f
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Aug 12, 2022
408a726
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Aug 22, 2022
ab27d13
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Aug 23, 2022
bfab646
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Aug 24, 2022
3841573
as per review
zeripath Aug 24, 2022
2dbfc50
Fix tests
zeripath Aug 24, 2022
0ff8921
placate lint
zeripath Aug 24, 2022
a442905
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Aug 27, 2022
c5bdfef
Update modules/templates/htmlrenderer.go
zeripath Aug 27, 2022
55c4ec6
placate lint
zeripath Aug 27, 2022
f7a5cd7
as per wxiaoguang
zeripath Aug 28, 2022
aec5c2f
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Aug 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Switch to use syncthing/notify instead of fsnotify/fsnotify"
This reverts commit 959595b.

syncthing/notify opens goroutines etc even on prod mode.

This is unacceptable and therefore we should stick with fsnotify which
is already a dependency because of unrolled.
zeripath committed Jul 17, 2022
commit 426eb8ff5482cf966e2a50e45b4312d3969e7f15
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ require (
github.com/emirpasic/gods v1.18.1
github.com/ethantkoenig/rupture v1.0.1
github.com/felixge/fgprof v0.9.2
github.com/fsnotify/fsnotify v1.5.4
zeripath marked this conversation as resolved.
Show resolved Hide resolved
github.com/gliderlabs/ssh v0.3.4
github.com/go-ap/activitypub v0.0.0-20220615144428-48208c70483b
github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d
@@ -81,7 +82,6 @@ require (
github.com/sergi/go-diff v1.2.0
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
github.com/stretchr/testify v1.7.1
github.com/syncthing/notify v0.0.0-20210616190510-c6b7342338d2
github.com/syndtr/goleveldb v1.0.0
github.com/tstranex/u2f v1.0.0
github.com/unrolled/render v1.4.1
@@ -161,7 +161,6 @@ require (
github.com/envoyproxy/protoc-gen-validate v0.6.2 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fullstorydev/grpcurl v1.8.1 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f // indirect
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1474,8 +1474,6 @@ github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMT
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syncthing/notify v0.0.0-20210616190510-c6b7342338d2 h1:F4snRP//nIuTTW9LYEzVH4HVwDG9T3M4t8y/2nqMbiY=
github.com/syncthing/notify v0.0.0-20210616190510-c6b7342338d2/go.mod h1:J0q59IWjLtpRIJulohwqEZvjzwOfTEPp8SVhDJl+y0Y=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
@@ -1842,7 +1840,6 @@ golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
46 changes: 25 additions & 21 deletions modules/watcher/watcher.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"

"github.com/syncthing/notify"
"github.com/fsnotify/fsnotify"
)

type CreateWatcherOpts struct {
@@ -39,57 +39,61 @@ func run(ctx context.Context, desc string, opts *CreateWatcherOpts) {
log.Trace("Watcher loop starting for %s", desc)
defer log.Trace("Watcher loop ended for %s", desc)

// Make the channel buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
events := make(chan notify.EventInfo, 1)

watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Error("Unable to create watcher for %s: %v", desc, err)
return
}
if err := opts.PathsCallback(func(path, _ string, _ fs.DirEntry, err error) error {
if err != nil && !os.IsNotExist(err) {
return err
}
log.Trace("Watcher: %s watching %q", desc, path)
if err := notify.Watch(path, events, notify.All); err != nil {
log.Trace("Watcher: %s unable to watch %q: error %v", desc, path, err)
}
_ = watcher.Add(path)
return nil
}); err != nil {
log.Error("Unable to create watcher for %s: %v", desc, err)
notify.Stop(events)
_ = watcher.Close()
return
}

// Note we don't call the BetweenCallback here

for {
select {
case event, ok := <-events:
case event, ok := <-watcher.Events:
if !ok {
notify.Stop(events)
_ = watcher.Close()
return
}

log.Debug("Watched file for %s had event: %v", desc, event)
case err, ok := <-watcher.Errors:
if !ok {
_ = watcher.Close()
return
}
log.Error("Error whilst watching files for %s: %v", desc, err)
case <-ctx.Done():
notify.Stop(events)
_ = watcher.Close()
return
}

// Recreate the watcher - only call the BetweenCallback after the new watcher is set-up
notify.Stop(events)
events = make(chan notify.EventInfo, 1)

_ = watcher.Close()
watcher, err = fsnotify.NewWatcher()
if err != nil {
log.Error("Unable to create watcher for %s: %v", desc, err)
return
}
if err := opts.PathsCallback(func(path, _ string, _ fs.DirEntry, err error) error {
if err != nil {
return err
}
log.Trace("Watcher: %s watching %q", desc, path)
if err := notify.Watch(path, events, notify.All); err != nil {
log.Trace("Watcher: %s unable to watch %q: error %v", desc, path, err)
}
_ = watcher.Add(path)
return nil
}); err != nil {
log.Error("Unable to create watcher for %s: %v", desc, err)
notify.Stop(events)
_ = watcher.Close()
return
}