Added skip rules, which mark new opportunities Skipped when they're fetched

sources.skip_rules_file names a JSON file of filters, each with a
comment, an active flag, a logic mode ("or" by default, or "and") and
rules by buyer, title words or CPV codes. The fetcher applies them
before saving, so only new opportunities are marked; the marks of
stored ones are never touched. CPV rules match when the opportunity's
codes are all in the list, or any of them with exclusive false, and
by prefix with exact false.

The file is read again when its time or size changes: an invalid edit
is logged and the last good rules kept, and a deleted file means no
rules until it's back. fetcher service and serve refuse to start if it
is define but missing or invalid.

job-search skip-rules check validates a rules file, and skip-rules
apply marks the stored opportunities that match Skipped, or only lists
them with --dry-run.
This commit is contained in:
bwilliams committed 2026-10-20 08:55:19 +01:00
1 parent 2e6c21f9dd
commit 0543762330
21 files changed
+1766 -8

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
package skiprules
import (
"fmt"
"log/slog"
"github.com/spf13/cobra"
"git.avsdev.uk/Go/job-search/internal/cli"
)
// commandCheck returns the "check" command, which reports whether a rules
// file is valid.
func commandCheck(opts *cli.Options) *cobra.Command {
return &cobra.Command{
Use: "check [file]",
Short: "Check a skip rules file (default: sources.skip_rules_file)",
Args: cobra.MaximumNArgs(1),
PersistentPreRun: func(cmd *cobra.Command, args []string) {
slog.Debug("command persistent pre-run", "command", "skip-rules.check")
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
slog.Debug("command persistent post-run", "command", "skip-rules.check")
},
RunE: func(cmd *cobra.Command, args []string) error {
slog.Debug("command run", "command", "skip-rules.check")
conf, err := opts.RunSetup(cmd, true, true)
if err != nil {
return fmt.Errorf("load configuration: %w", err)
}
rules, path, err := loadRules(conf, args)
if err != nil {
return err
}
_, err = fmt.Fprintf(
cmd.OutOrStdout(), "%s is valid: %s\n", path, describeRules(rules),
)
return err
},
}
}