Skip to content

Commit 6716356

Browse files
committed
Add Grok runner workflows and improve mutex handling
Introduce new workflows for the Grok runner, including initialization (`init`), chat completions, and context canceled tasks. Refactor mutex usage in API handlers for better synchronization and clean up configuration patterns in YAML file scanning.
1 parent 0ffaa5d commit 6716356

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

internal/api/handlers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/google/uuid"
1717
)
1818

19-
var mutex sync.Mutex
19+
var RequestMutex sync.Mutex
2020

2121
// APIHandlers contains the handlers for API endpoints
2222
type APIHandlers struct {
@@ -38,8 +38,8 @@ func NewAPIHandlers(appConfig *config.AppConfig, queue *RequestQueue, pages map[
3838

3939
// ChatCompletions handles the /v1/chat/completions endpoint
4040
func (h *APIHandlers) ChatCompletions(c *gin.Context) {
41-
defer mutex.Unlock()
42-
mutex.Lock()
41+
defer RequestMutex.Unlock()
42+
RequestMutex.Lock()
4343
rawJson, err := c.GetRawData()
4444
// If data retrieval fails, return 400 error
4545
if err != nil {

internal/runner/manager.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ func (rm *RunnerManager) LoadConfiguration(name, path string) error {
114114
// LoadConfigurations scans all yaml files in the runner directory and calls LoadConfiguration method by filename
115115
func (rm *RunnerManager) LoadConfigurations() error {
116116
// Scan all yaml and yml files in the runner directory
117-
yamlFiles, err := filepath.Glob(fmt.Sprintf("runner/%s/*.yaml", rm.name))
117+
pattern := filepath.Join("runner", rm.name, "*.yaml")
118+
yamlFiles, err := filepath.Glob(pattern)
118119
if err != nil {
119120
return fmt.Errorf("failed to scan yaml files: %v", err)
120121
}
121122

122-
ymlFiles, err := filepath.Glob(fmt.Sprintf("runner/%s/*.yml", rm.name))
123+
pattern = filepath.Join("runner", rm.name, "*.yml")
124+
ymlFiles, err := filepath.Glob(pattern)
123125
if err != nil {
124126
return fmt.Errorf("failed to scan yml files: %v", err)
125127
}

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ func main() {
235235
}
236236

237237
if saveState {
238+
api.RequestMutex.Lock()
238239
storageState, errStorageState := p.Context().StorageState()
240+
api.RequestMutex.Unlock()
239241
if errStorageState != nil {
240242
log.Debugf("Error getting storage state: %v", err)
241243
continue

0 commit comments

Comments
 (0)