feeds.Executed
parent
88ab880a8c
commit
7f97eecbca
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue