diff --git a/src/feeds/db.go b/src/feeds/db.go index dde9229..3fe1342 100644 --- a/src/feeds/db.go +++ b/src/feeds/db.go @@ -193,6 +193,19 @@ func (f *Feeds) oldGet(ctx context.Context, id string) (Feed, error) { return Feed{}, fmt.Errorf("%+v, %+v, %+v", entry, version, execution) } +func (f *Feeds) Executed(ctx context.Context, id string, version time.Time) error { + now := time.Now() + return db.Exec(ctx, ` + INSERT INTO "feed.executions" ( + entries_id, + versions_created_at, + executed_at + ) VALUES (?, ?, ?); + `, + id, version, now, + ) +} + func (f *Feeds) Insert(ctx context.Context, url, cron string) (string, error) { now := time.Now() id := uuid.New().String() diff --git a/src/feeds/db_test.go b/src/feeds/db_test.go index df3bff7..545f3b8 100644 --- a/src/feeds/db_test.go +++ b/src/feeds/db_test.go @@ -82,5 +82,27 @@ func TestFeeds(t *testing.T) { if !got.Execution.Version.IsZero() { t.Error("execution.version") } + + if err := f.Executed(ctx, got.Entry.ID, got.Version.Created); err != nil { + t.Fatal("cannot executed:", err) + } + + got2, err := f.Get(ctx, id) + if err != nil { + t.Fatal("cannot get w executed:", err) + } + t.Logf("%+v", got2) + + if got2.Execution.Executed.IsZero() { + t.Error("no execution.executed") + } + if got2.Execution.Version != got.Version.Created { + t.Errorf("bad execution.version: expected %v but got %v (difference of %v)", got.Version.Created, got2.Execution.Version, got2.Execution.Version.Sub(got.Execution.Version)) + } + + got2.Execution = got.Execution + if got != got2 { + t.Errorf("changes after execution: was \n\t%+v but now \n\t%+v", got, got2) + } }) }