feeds.versions have a pattern

main
Bel LaPointe 2025-04-27 11:58:00 -06:00
parent 18fd8dfac5
commit a097814a62
4 changed files with 18 additions and 10 deletions

View File

@ -53,5 +53,5 @@ func one(ctx context.Context, feed feeds.Feed) error {
return fmt.Errorf("should parse %s", feed.Version.URL)
return feeds.Executed(ctx, feed.Entry.ID, feed.Version.Created)
return feed.Executed(ctx)
}

View File

@ -39,7 +39,7 @@ func TestOne(t *testing.T) {
ctx := db.Test(t, ctx)
for i := 0; i < 2; i++ {
if _, err := feeds.Insert(ctx, fmt.Sprintf("%s?idx=%d", s.URL, i), "* * * * *"); err != nil {
if _, err := feeds.Insert(ctx, fmt.Sprintf("%s?idx=%d", s.URL, i), "* * * * *", "matches"); err != nil {
t.Fatal(err)
}
}

View File

@ -29,6 +29,7 @@ type (
Created time.Time
URL string
Cron string
Pattern string
}
Execution struct {
@ -95,6 +96,7 @@ func Get(ctx context.Context, id string) (Feed, error) {
versions.created_at AS "Version.Created",
versions.url AS "Version.URL",
versions.cron AS "Version.Cron",
versions.pattern AS "Version.Pattern",
(
SELECT executed_at
FROM "feed.executions"
@ -130,8 +132,9 @@ func oldGet(ctx context.Context, id string) (Feed, error) {
version, err := db.QueryOne[Version](ctx, `
SELECT
"feed.current_versions".versions_created_at AS Created,
"feed.current_versions" AS URL,
"feed.current_versions" AS Cron
"feed.current_versions".url AS URL,
"feed.current_versions".cron AS Cron,
"feed.current_versions".pattern AS Pattern
FROM
"feed.current_versions"
JOIN
@ -184,7 +187,7 @@ func (feed Feed) Executed(ctx context.Context) error {
)
}
func Insert(ctx context.Context, url, cron string) (string, error) {
func Insert(ctx context.Context, url, cron, pattern string) (string, error) {
if err := initDB(ctx); err != nil {
return "", err
}
@ -202,16 +205,17 @@ func Insert(ctx context.Context, url, cron string) (string, error) {
entries_id,
created_at,
url,
cron
) VALUES ($4, $5, $6, $7);
cron,
pattern
) VALUES ($4, $5, $6, $7, $8);
COMMIT;
`,
id, now, now,
id, now, url, cron,
id, now, url, cron, pattern,
)
}
func (feed Feed) Update(ctx context.Context, url, cron *string) error {
func (feed Feed) Update(ctx context.Context, url, cron, pattern *string) error {
return io.EOF
}
@ -271,6 +275,7 @@ func initDB(ctx context.Context) error {
)`,
`ALTER TABLE "feed.versions" ADD COLUMN url TEXT NOT NULL`,
`ALTER TABLE "feed.versions" ADD COLUMN cron TEXT NOT NULL DEFAULT '0 0 * * *'`,
`ALTER TABLE "feed.versions" ADD COLUMN pattern TEXT NOT NULL DEFAULT ''`,
`CREATE TABLE "feed.executions" (
entries_id TEXT,

View File

@ -15,7 +15,7 @@ func TestFeeds(t *testing.T) {
t.Run("crud", func(t *testing.T) {
ctx := db.Test(t, ctx)
id, err := feeds.Insert(ctx, "url", "cron")
id, err := feeds.Insert(ctx, "url", "cron", "pattern")
if err != nil {
t.Fatal("cannot insert:", err)
}
@ -48,6 +48,9 @@ func TestFeeds(t *testing.T) {
if got.Version.Cron != "cron" {
t.Error("no version.cron")
}
if got.Version.Pattern != "pattern" {
t.Error("bad version.pattern")
}
if !got.Execution.Executed.IsZero() {
t.Error("execution.executed")