Merge pull request #2474 from srcrs/fix-cron-independent-sessions
fix(cron): make each job execution use an independent session
This commit is contained in:
commit
ba08d52351
2 changed files with 5 additions and 3 deletions
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/sipeed/picoclaw/pkg/bus"
|
"github.com/sipeed/picoclaw/pkg/bus"
|
||||||
"github.com/sipeed/picoclaw/pkg/config"
|
"github.com/sipeed/picoclaw/pkg/config"
|
||||||
"github.com/sipeed/picoclaw/pkg/constants"
|
"github.com/sipeed/picoclaw/pkg/constants"
|
||||||
|
|
@ -340,7 +342,7 @@ func (t *CronTool) ExecuteJob(ctx context.Context, job *cron.CronJob) string {
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionKey := fmt.Sprintf("cron-%s", job.ID)
|
sessionKey := fmt.Sprintf("agent:cron-%s-%s", job.ID, uuid.New().String())
|
||||||
|
|
||||||
// Call agent with the job message
|
// Call agent with the job message
|
||||||
response, err := t.executor.ProcessDirectWithChannel(
|
response, err := t.executor.ProcessDirectWithChannel(
|
||||||
|
|
|
||||||
|
|
@ -271,8 +271,8 @@ func TestCronTool_ExecuteJobPublishesAgentResponse(t *testing.T) {
|
||||||
t.Fatalf("ExecuteJob() = %q, want ok", got)
|
t.Fatalf("ExecuteJob() = %q, want ok", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if executor.lastKey != "cron-job-1" {
|
if !strings.HasPrefix(executor.lastKey, "agent:cron-job-1-") {
|
||||||
t.Fatalf("sessionKey = %q, want cron-job-1", executor.lastKey)
|
t.Fatalf("sessionKey = %q, want agent:cron-job-1-{uuid}", executor.lastKey)
|
||||||
}
|
}
|
||||||
if executor.lastChan != "telegram" || executor.lastChatID != "chat-1" {
|
if executor.lastChan != "telegram" || executor.lastChatID != "chat-1" {
|
||||||
t.Fatalf("executor target = %s/%s, want telegram/chat-1", executor.lastChan, executor.lastChatID)
|
t.Fatalf("executor target = %s/%s, want telegram/chat-1", executor.lastChan, executor.lastChatID)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue