wip: port queue.StartAnalyses
This commit is contained in:
committed by
=Michael Hohn
parent
cf595f338a
commit
8cd4f4d809
31
pkg/queue/queue.go
Normal file
31
pkg/queue/queue.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package queue
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/slog"
|
||||||
|
"mrvacommander/pkg/storage"
|
||||||
|
|
||||||
|
co "github.com/hohn/ghes-mirva-server/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
NumWorkers int
|
||||||
|
Jobs chan co.AnalyzeJob
|
||||||
|
Results chan co.AnalyzeResult
|
||||||
|
)
|
||||||
|
|
||||||
|
func StartAnalyses(analysis_repos *map[co.OwnerRepo]storage.DBLocation, session_id int,
|
||||||
|
session_language string) {
|
||||||
|
slog.Debug("Queueing codeql database analyze jobs")
|
||||||
|
|
||||||
|
for orl := range *analysis_repos {
|
||||||
|
info := co.AnalyzeJob{
|
||||||
|
QueryPackId: session_id,
|
||||||
|
QueryLanguage: session_language,
|
||||||
|
|
||||||
|
ORL: orl,
|
||||||
|
}
|
||||||
|
Jobs <- info
|
||||||
|
storage.SetStatus(session_id, orl, co.StatusQueued)
|
||||||
|
storage.AddJob(session_id, info)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"mrvacommander/pkg/queue"
|
||||||
"mrvacommander/pkg/storage"
|
"mrvacommander/pkg/storage"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@@ -290,8 +291,7 @@ func (c *CommanderSingle) MirvaRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
not_found_repos, analysisRepos := c.st.Storage.FindAvailableDBs(session_repositories)
|
not_found_repos, analysisRepos := c.st.Storage.FindAvailableDBs(session_repositories)
|
||||||
|
|
||||||
// TODO into Queue
|
queue.StartAnalyses(analysisRepos, session_id, session_language)
|
||||||
// session_start_analyses()
|
|
||||||
|
|
||||||
// TODO into Commander (here)
|
// TODO into Commander (here)
|
||||||
si := SessionInfo{
|
si := SessionInfo{
|
||||||
|
|||||||
@@ -210,3 +210,15 @@ func ResultAsFile(path string) (string, []byte, error) {
|
|||||||
|
|
||||||
return fpath, file, nil
|
return fpath, file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetStatus(sessionid int, orl co.OwnerRepo, s co.Status) {
|
||||||
|
mutex.Lock()
|
||||||
|
defer mutex.Unlock()
|
||||||
|
status[co.JobSpec{ID: sessionid, OwnerRepo: orl}] = s
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddJob(sessionid int, job co.AnalyzeJob) {
|
||||||
|
mutex.Lock()
|
||||||
|
defer mutex.Unlock()
|
||||||
|
jobs[sessionid] = append(jobs[sessionid], job)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user