diff options
Diffstat (limited to 'internal/storage/db.go')
| -rw-r--r-- | internal/storage/db.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/storage/db.go b/internal/storage/db.go index 69bcf68..a77b1b1 100644 --- a/internal/storage/db.go +++ b/internal/storage/db.go @@ -146,6 +146,10 @@ func (s *DB) ListTasks(filter TaskFilter) ([]*task.Task, error) { query += " AND state = ?" args = append(args, string(filter.State)) } + if !filter.Since.IsZero() { + query += " AND updated_at > ?" + args = append(args, filter.Since.UTC()) + } query += " ORDER BY created_at DESC" if filter.Limit > 0 { query += " LIMIT ?" @@ -350,6 +354,33 @@ func (s *DB) UpdateTask(id string, u TaskUpdate) error { type TaskFilter struct { State task.State Limit int + Since time.Time +} + +// GetMaxUpdatedAt returns the most recent updated_at timestamp across all tasks. +func (s *DB) GetMaxUpdatedAt() (time.Time, error) { + var t sql.NullString + err := s.db.QueryRow(`SELECT MAX(updated_at) FROM tasks`).Scan(&t) + if err != nil { + return time.Time{}, err + } + if !t.Valid || t.String == "" { + return time.Time{}, nil + } + // Try parsing different formats SQLite might return + formats := []string{ + "2006-01-02 15:04:05.999999999-07:00", + "2006-01-02T15:04:05Z07:00", + time.RFC3339, + "2006-01-02 15:04:05", + } + for _, f := range formats { + parsed, err := time.Parse(f, t.String) + if err == nil { + return parsed.UTC(), nil + } + } + return time.Time{}, fmt.Errorf("could not parse max updated_at: %q", t.String) } // Execution represents a single run of a task. |
