7
7
"encoding/json"
8
8
"errors"
9
9
"fmt"
10
+ "log/slog"
10
11
"strings"
11
12
"time"
12
13
@@ -17,7 +18,6 @@ import (
17
18
"github.com/cschleiden/go-workflows/internal/history"
18
19
"github.com/cschleiden/go-workflows/internal/metrickeys"
19
20
"github.com/cschleiden/go-workflows/internal/task"
20
- "github.com/cschleiden/go-workflows/log"
21
21
"github.com/cschleiden/go-workflows/metrics"
22
22
"github.com/cschleiden/go-workflows/workflow"
23
23
"github.com/google/uuid"
@@ -67,7 +67,7 @@ type sqliteBackend struct {
67
67
68
68
var _ backend.Backend = (* sqliteBackend )(nil )
69
69
70
- func (sb * sqliteBackend ) Logger () log .Logger {
70
+ func (sb * sqliteBackend ) Logger () * slog .Logger {
71
71
return sb .options .Logger
72
72
}
73
73
@@ -288,7 +288,7 @@ func (sb *sqliteBackend) GetWorkflowTask(ctx context.Context) (*task.Workflow, e
288
288
WHERE
289
289
(locked_until IS NULL OR locked_until < ?)
290
290
AND (sticky_until IS NULL OR sticky_until < ? OR worker = ?)
291
- AND completed_at IS NULL
291
+ AND state = ? AND i. completed_at IS NULL
292
292
AND EXISTS (
293
293
SELECT 1
294
294
FROM pending_events
@@ -298,10 +298,11 @@ func (sb *sqliteBackend) GetWorkflowTask(ctx context.Context) (*task.Workflow, e
298
298
) RETURNING id, execution_id, parent_instance_id, parent_execution_id, parent_schedule_event_id, metadata, sticky_until` ,
299
299
now .Add (sb .options .WorkflowLockTimeout ), // new locked_until
300
300
sb .workerName ,
301
- now , // locked_until
302
- now , // sticky_until
303
- sb .workerName , // worker
304
- now , // event.visible_at
301
+ now , // locked_until
302
+ now , // sticky_until
303
+ sb .workerName , // worker
304
+ core .WorkflowInstanceStateActive , // state
305
+ now , // pending_event.visible_at
305
306
)
306
307
307
308
var instanceID , executionID string
@@ -383,7 +384,7 @@ func (sb *sqliteBackend) CompleteWorkflowTask(
383
384
defer tx .Rollback ()
384
385
385
386
var completedAt * time.Time
386
- if state == core .WorkflowInstanceStateFinished || state == core .WorkflowInstanceStateContinuedAsNew {
387
+ if state == core .WorkflowInstanceStateContinuedAsNew || state == core .WorkflowInstanceStateFinished {
387
388
t := time .Now ()
388
389
completedAt = & t
389
390
}
0 commit comments