Fix queue & warn about queued or cancelled search
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var cancelled = make(map[string]struct{})
|
||||||
|
|
||||||
func searchWorker(s *server.Server, cache *map[string]*search.Result, searchQueue chan string, limiter chan struct{}) {
|
func searchWorker(s *server.Server, cache *map[string]*search.Result, searchQueue chan string, limiter chan struct{}) {
|
||||||
for id := range searchQueue {
|
for id := range searchQueue {
|
||||||
s.Mu.RLock()
|
s.Mu.RLock()
|
||||||
@@ -21,6 +23,16 @@ func searchWorker(s *server.Server, cache *map[string]*search.Result, searchQueu
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.Mu.RLock()
|
||||||
|
_, isCancelled := cancelled[id]
|
||||||
|
s.Mu.RUnlock()
|
||||||
|
if isCancelled {
|
||||||
|
s.Mu.Lock()
|
||||||
|
r.Status = "cancelled"
|
||||||
|
s.Mu.Unlock()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
limiter <- struct{}{}
|
limiter <- struct{}{}
|
||||||
search.Search(s, r.Query, r, s.Mu)
|
search.Search(s, r.Query, r, s.Mu)
|
||||||
<-limiter
|
<-limiter
|
||||||
@@ -130,30 +142,14 @@ func routes(s *server.Server, cache *map[string]*search.Result, searchQueue chan
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Status == "queued" {
|
|
||||||
newQueue := make(chan string, cap(searchQueue))
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case queuedId := <-searchQueue:
|
|
||||||
if queuedId != id {
|
|
||||||
newQueue <- queuedId
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
goto Done
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Done:
|
|
||||||
searchQueue = newQueue
|
|
||||||
|
|
||||||
s.Mu.Lock()
|
s.Mu.Lock()
|
||||||
|
cancelled[id] = struct{}{}
|
||||||
|
if r.Status == "queued" {
|
||||||
r.Status = "cancelled"
|
r.Status = "cancelled"
|
||||||
|
}
|
||||||
s.Mu.Unlock()
|
s.Mu.Unlock()
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"Status": "Cancelled"})
|
c.JSON(http.StatusOK, gin.H{"Status": "Cancelled"})
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"Error": "Cannot cancel running or finished search"})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
s.Router.GET("/dataleak/sample", func(c *gin.Context) {
|
s.Router.GET("/dataleak/sample", func(c *gin.Context) {
|
||||||
|
|||||||
@@ -43,7 +43,11 @@
|
|||||||
.then((r) => {
|
.then((r) => {
|
||||||
result = r.data;
|
result = r.data;
|
||||||
console.log(result);
|
console.log(result);
|
||||||
if (result && result.Status !== "pending") {
|
if (
|
||||||
|
result &&
|
||||||
|
result.Status !== "pending" &&
|
||||||
|
result.Status !== "queued"
|
||||||
|
) {
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -71,7 +75,7 @@
|
|||||||
elapsedTime += pollingInterval;
|
elapsedTime += pollingInterval;
|
||||||
|
|
||||||
// Check for status change inside the interval
|
// Check for status change inside the interval
|
||||||
if (result && result.Status !== "pending") {
|
if (result && result.Status !== "pending" && result.Status !== "queued") {
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -122,6 +126,17 @@
|
|||||||
<Stats {result} />
|
<Stats {result} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if result.Status === "queued"}
|
||||||
|
<div class="my-10 m-auto flex gap-5 flex-col">
|
||||||
|
<h2 class="text-center font-bold text-8xl">(o^^)o</h2>
|
||||||
|
<h2 class="text-center font-semibold text-4xl">Search queued...</h2>
|
||||||
|
</div>
|
||||||
|
{:else if result.Status === "cancelled"}
|
||||||
|
<div class="my-10 m-auto flex gap-5 flex-col">
|
||||||
|
<h2 class="text-center font-bold text-8xl">(^-^*)</h2>
|
||||||
|
<h2 class="text-center font-semibold text-4xl">Search cancelled</h2>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
{#if !result.LeakResult.Inactive}
|
{#if !result.LeakResult.Inactive}
|
||||||
<div class="collapse collapse-arrow bg-base-100 border">
|
<div class="collapse collapse-arrow bg-base-100 border">
|
||||||
<input type="radio" name="my-accordion-2" checked={true} />
|
<input type="radio" name="my-accordion-2" checked={true} />
|
||||||
@@ -299,6 +314,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user