mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
add wait enabled.
This commit is contained in:
@@ -31,6 +31,7 @@ type Room struct {
|
||||
NekoPrivilegedImages []string
|
||||
PathPrefix string
|
||||
Labels []string
|
||||
WaitEnabled bool
|
||||
|
||||
StorageEnabled bool
|
||||
StorageInternal string
|
||||
@@ -93,6 +94,11 @@ func (Room) Init(cmd *cobra.Command) error {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().Bool("wait_enabled", true, "enable active waiting for the room")
|
||||
if err := viper.BindPFlag("wait_enabled", cmd.PersistentFlags().Lookup("wait_enabled")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Data
|
||||
|
||||
cmd.PersistentFlags().Bool("storage.enabled", true, "whether storage is enabled, where peristent containers data will be stored")
|
||||
@@ -199,6 +205,7 @@ func (s *Room) Set() {
|
||||
s.NekoPrivilegedImages = viper.GetStringSlice("neko_privileged_images")
|
||||
s.PathPrefix = path.Join("/", path.Clean(viper.GetString("path_prefix")))
|
||||
s.Labels = viper.GetStringSlice("labels")
|
||||
s.WaitEnabled = viper.GetBool("wait_enabled")
|
||||
|
||||
s.StorageEnabled = viper.GetBool("storage.enabled")
|
||||
s.StorageInternal = viper.GetString("storage.internal")
|
||||
|
||||
@@ -40,7 +40,7 @@ func roomWait(w http.ResponseWriter, r *http.Request) {
|
||||
</script>`))
|
||||
}
|
||||
|
||||
func RoomNotFound(w http.ResponseWriter, r *http.Request) {
|
||||
func RoomNotFound(w http.ResponseWriter, r *http.Request, waitEnabled bool) {
|
||||
utils.Swal2Response(w, `
|
||||
<div class="swal2-header">
|
||||
<div class="swal2-icon swal2-error">
|
||||
@@ -57,10 +57,12 @@ func RoomNotFound(w http.ResponseWriter, r *http.Request) {
|
||||
</div>
|
||||
`)
|
||||
|
||||
roomWait(w, r)
|
||||
if waitEnabled {
|
||||
roomWait(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func RoomNotRunning(w http.ResponseWriter, r *http.Request) {
|
||||
func RoomNotRunning(w http.ResponseWriter, r *http.Request, waitEnabled bool) {
|
||||
utils.Swal2Response(w, `
|
||||
<div class="swal2-header">
|
||||
<div class="swal2-icon swal2-warning">
|
||||
@@ -77,7 +79,9 @@ func RoomNotRunning(w http.ResponseWriter, r *http.Request) {
|
||||
</div>
|
||||
`)
|
||||
|
||||
roomWait(w, r)
|
||||
if waitEnabled {
|
||||
roomWait(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func RoomNotReady(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
+17
-13
@@ -35,21 +35,23 @@ type ProxyManagerCtx struct {
|
||||
ctx context.Context
|
||||
cancel func()
|
||||
|
||||
waitMu sync.RWMutex
|
||||
waitChans map[string]*wait
|
||||
waitMu sync.RWMutex
|
||||
waitChans map[string]*wait
|
||||
waitEnabled bool
|
||||
|
||||
client *dockerClient.Client
|
||||
instanceName string
|
||||
handlers *prefixHandler[*entry]
|
||||
}
|
||||
|
||||
func New(client *dockerClient.Client, instanceName string) *ProxyManagerCtx {
|
||||
func New(client *dockerClient.Client, instanceName string, waitEnabled bool) *ProxyManagerCtx {
|
||||
return &ProxyManagerCtx{
|
||||
logger: log.With().Str("module", "proxy").Logger(),
|
||||
waitChans: map[string]*wait{},
|
||||
|
||||
client: client,
|
||||
instanceName: instanceName,
|
||||
waitEnabled: waitEnabled,
|
||||
handlers: &prefixHandler[*entry]{},
|
||||
}
|
||||
}
|
||||
@@ -94,13 +96,15 @@ func (p *ProxyManagerCtx) Start() {
|
||||
Msg("got docker event")
|
||||
|
||||
// terminate waiting for any events
|
||||
p.waitMu.Lock()
|
||||
ch, ok := p.waitChans[path]
|
||||
if ok {
|
||||
close(ch.signal)
|
||||
delete(p.waitChans, path)
|
||||
if p.waitEnabled {
|
||||
p.waitMu.Lock()
|
||||
ch, ok := p.waitChans[path]
|
||||
if ok {
|
||||
close(ch.signal)
|
||||
delete(p.waitChans, path)
|
||||
}
|
||||
p.waitMu.Unlock()
|
||||
}
|
||||
p.waitMu.Unlock()
|
||||
|
||||
p.mu.Lock()
|
||||
switch msg.Action {
|
||||
@@ -286,12 +290,12 @@ func (p *ProxyManagerCtx) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// if room not found
|
||||
if !ok {
|
||||
// blocking until room is created
|
||||
if r.URL.Query().Has("wait") {
|
||||
if r.URL.Query().Has("wait") && p.waitEnabled {
|
||||
p.waitForPath(w, r, cleanPath)
|
||||
return
|
||||
}
|
||||
|
||||
RoomNotFound(w, r)
|
||||
RoomNotFound(w, r, p.waitEnabled)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -305,12 +309,12 @@ func (p *ProxyManagerCtx) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// if room not running
|
||||
if !proxy.running {
|
||||
// blocking until room is running
|
||||
if r.URL.Query().Has("wait") {
|
||||
if r.URL.Query().Has("wait") && p.waitEnabled {
|
||||
p.waitForPath(w, r, cleanPath)
|
||||
return
|
||||
}
|
||||
|
||||
RoomNotRunning(w, r)
|
||||
RoomNotRunning(w, r, p.waitEnabled)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user