Add a job leads inbox that finds and scores postings
The tracker recorded applications but could not find jobs. A new pipeline (services/job_leads.go, job_sources.go) polls a watch list of sources on a timer or on request, files unseen postings as leads, marks which pass a keyword and location pre-filter, and has Claude score those against a single search profile through a fourth internal Python route, /internal/jobs/score. Sources are Greenhouse, Lever and Ashby company boards (public JSON) and Adzuna and Reed keyword searches (API keys). The two search fetchers are written from the providers' documentation and tested only against stubs. Leads are their own table, not a job status, and are not soft deleted: the (source_kind, external_id) index is the dedup, so a dismissed lead has to remain a row. A lead reaches the tracker only by promotion, which goes through UpsertJobApplication. That upsert moves from the capture handler into services so promotion and the fetcher can share it; the capture endpoint's behaviour is unchanged. /cv/leads is the page: inbox, watch list and profile form. The timer is off unless JOB_LEADS_ENABLED=true and never runs at start-up, so a deploy spends no Claude calls. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -187,12 +187,17 @@ func TestSignedInMutationsArePinned(t *testing.T) {
|
||||
// `spotifyNeedsReauth` is false for non-admins.
|
||||
func TestGuardedQueriesArePinned(t *testing.T) {
|
||||
want := map[string]string{
|
||||
"users": "admin",
|
||||
"user": "admin",
|
||||
"jobApplications": "admin",
|
||||
"jobApplication": "admin",
|
||||
"jobAppReferences": "admin",
|
||||
"places": "signedIn",
|
||||
"users": "admin",
|
||||
"user": "admin",
|
||||
"jobApplications": "admin",
|
||||
"jobApplication": "admin",
|
||||
"jobAppReferences": "admin",
|
||||
"jobSources": "admin",
|
||||
"jobLeads": "admin",
|
||||
"jobLead": "admin",
|
||||
"jobSearchProfile": "admin",
|
||||
"jobLeadSyncStatus": "admin",
|
||||
"places": "signedIn",
|
||||
}
|
||||
got := map[string]string{}
|
||||
for _, field := range schemaUnderTest().Query.Fields {
|
||||
|
||||
+2972
-23
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,204 @@
|
||||
package graph
|
||||
|
||||
// This file will be automatically regenerated based on the schema, any resolver
|
||||
// implementations
|
||||
// will be copied through when generating and any unknown code will be moved to the end.
|
||||
// Code generated by github.com/99designs/gqlgen version v0.17.95
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"adam-french.co.uk/backend/graph/model"
|
||||
"adam-french.co.uk/backend/models"
|
||||
"adam-french.co.uk/backend/services"
|
||||
)
|
||||
|
||||
// CreateJobSource is the resolver for the createJobSource field.
|
||||
func (r *mutationResolver) CreateJobSource(ctx context.Context, input model.CreateJobSourceInput) (*models.JobSource, error) {
|
||||
src := models.JobSource{Kind: input.Kind, Label: input.Label, Enabled: true}
|
||||
if input.Token != nil {
|
||||
src.Token = *input.Token
|
||||
}
|
||||
if input.Query != nil {
|
||||
src.Query = *input.Query
|
||||
}
|
||||
if input.Location != nil {
|
||||
src.Location = *input.Location
|
||||
}
|
||||
if input.Enabled != nil {
|
||||
src.Enabled = *input.Enabled
|
||||
}
|
||||
if err := services.ValidateJobSource(&src); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := r.Store.DB.Create(&src).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &src, nil
|
||||
}
|
||||
|
||||
// UpdateJobSource is the resolver for the updateJobSource field.
|
||||
func (r *mutationResolver) UpdateJobSource(ctx context.Context, id int, input model.UpdateJobSourceInput) (*models.JobSource, error) {
|
||||
// Partial update, as in UpdateJobApplication: a nil field is untouched.
|
||||
// The merged row is validated as a whole, because whether a token or a
|
||||
// query is required depends on the kind, which may itself be changing.
|
||||
var src models.JobSource
|
||||
if err := r.Store.DB.First(&src, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if input.Kind != nil {
|
||||
src.Kind = *input.Kind
|
||||
}
|
||||
if input.Label != nil {
|
||||
src.Label = *input.Label
|
||||
}
|
||||
if input.Token != nil {
|
||||
src.Token = *input.Token
|
||||
}
|
||||
if input.Query != nil {
|
||||
src.Query = *input.Query
|
||||
}
|
||||
if input.Location != nil {
|
||||
src.Location = *input.Location
|
||||
}
|
||||
if input.Enabled != nil {
|
||||
src.Enabled = *input.Enabled
|
||||
}
|
||||
if err := services.ValidateJobSource(&src); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Named columns rather than Save: the fetcher writes last_fetched_at,
|
||||
// last_count and last_error on this row during a run, and saving the
|
||||
// whole struct loaded above would put stale values back over them.
|
||||
if err := r.Store.DB.Model(&src).
|
||||
Select("Kind", "Label", "Token", "Query", "Location", "Enabled").
|
||||
Updates(&src).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &src, nil
|
||||
}
|
||||
|
||||
// DeleteJobSource is the resolver for the deleteJobSource field.
|
||||
func (r *mutationResolver) DeleteJobSource(ctx context.Context, id int) (bool, error) {
|
||||
// Loaded first so a missing id is an error; see DeleteJobApplication.
|
||||
// The source's leads are deliberately left alone: they are still real
|
||||
// postings, and deleting them would let a re-added source file every one
|
||||
// of them again, dismissed ones included.
|
||||
var src models.JobSource
|
||||
if err := r.Store.DB.First(&src, id).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err := r.Store.DB.Delete(&src).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// DismissJobLead is the resolver for the dismissJobLead field.
|
||||
func (r *mutationResolver) DismissJobLead(ctx context.Context, id int) (*models.JobLead, error) {
|
||||
return r.setLeadState(id, services.LeadNew, services.LeadDismissed)
|
||||
}
|
||||
|
||||
// RestoreJobLead is the resolver for the restoreJobLead field.
|
||||
func (r *mutationResolver) RestoreJobLead(ctx context.Context, id int) (*models.JobLead, error) {
|
||||
return r.setLeadState(id, services.LeadDismissed, services.LeadNew)
|
||||
}
|
||||
|
||||
// PromoteJobLead is the resolver for the promoteJobLead field.
|
||||
func (r *mutationResolver) PromoteJobLead(ctx context.Context, id int) (*models.JobLead, error) {
|
||||
return services.PromoteJobLead(r.Store.DB, uint(id), time.Now())
|
||||
}
|
||||
|
||||
// UpdateJobSearchProfile is the resolver for the updateJobSearchProfile field.
|
||||
func (r *mutationResolver) UpdateJobSearchProfile(ctx context.Context, input model.UpdateJobSearchProfileInput) (*models.JobSearchProfile, error) {
|
||||
profile, err := services.LoadJobSearchProfile(r.Store.DB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if input.Profile != nil {
|
||||
profile.Profile = *input.Profile
|
||||
}
|
||||
if input.IncludeKeywords != nil {
|
||||
profile.IncludeKeywords = strings.TrimSpace(*input.IncludeKeywords)
|
||||
}
|
||||
if input.ExcludeKeywords != nil {
|
||||
profile.ExcludeKeywords = strings.TrimSpace(*input.ExcludeKeywords)
|
||||
}
|
||||
if input.Locations != nil {
|
||||
profile.Locations = strings.TrimSpace(*input.Locations)
|
||||
}
|
||||
if input.MinScore != nil {
|
||||
profile.MinScore = *input.MinScore
|
||||
}
|
||||
if err := services.SaveJobSearchProfile(r.Store.DB, profile); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return profile, nil
|
||||
}
|
||||
|
||||
// RunJobLeadSync is the resolver for the runJobLeadSync field.
|
||||
func (r *mutationResolver) RunJobLeadSync(ctx context.Context) (bool, error) {
|
||||
if r.Store.JobLeads == nil {
|
||||
return false, fmt.Errorf("job leads are not configured")
|
||||
}
|
||||
return r.Store.JobLeads.RunInBackground(), nil
|
||||
}
|
||||
|
||||
// JobSources is the resolver for the jobSources field.
|
||||
func (r *queryResolver) JobSources(ctx context.Context) ([]*models.JobSource, error) {
|
||||
var sources []*models.JobSource
|
||||
if err := r.Store.DB.Order("label ASC, id ASC").Find(&sources).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sources, nil
|
||||
}
|
||||
|
||||
// JobLeads is the resolver for the jobLeads field.
|
||||
func (r *queryResolver) JobLeads(ctx context.Context, state *string, includeUnmatched *bool) ([]*models.JobLead, error) {
|
||||
// Omit, not Select: every column but the description, which is tens of
|
||||
// kilobytes a row and is fetched one lead at a time through jobLead. A
|
||||
// client that asks for description here gets "".
|
||||
query := r.Store.DB.Omit("description")
|
||||
if state != nil {
|
||||
query = query.Where("state = ?", *state)
|
||||
}
|
||||
if includeUnmatched == nil || !*includeUnmatched {
|
||||
// A promoted or dismissed lead is shown whatever the filter now says
|
||||
// about it; `matched` only decides what the inbox offers.
|
||||
query = query.Where("matched = ? OR state <> ?", true, services.LeadNew)
|
||||
}
|
||||
var leads []*models.JobLead
|
||||
// Best first, unscored after scored, newest first within a score. The
|
||||
// limit is a backstop for includeUnmatched on a database holding several
|
||||
// whole boards.
|
||||
if err := query.Order("score DESC NULLS LAST, created_at DESC, id DESC").Limit(2000).Find(&leads).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return leads, nil
|
||||
}
|
||||
|
||||
// JobLead is the resolver for the jobLead field.
|
||||
func (r *queryResolver) JobLead(ctx context.Context, id int) (*models.JobLead, error) {
|
||||
var lead models.JobLead
|
||||
if err := r.Store.DB.First(&lead, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &lead, nil
|
||||
}
|
||||
|
||||
// JobSearchProfile is the resolver for the jobSearchProfile field.
|
||||
func (r *queryResolver) JobSearchProfile(ctx context.Context) (*models.JobSearchProfile, error) {
|
||||
return services.LoadJobSearchProfile(r.Store.DB)
|
||||
}
|
||||
|
||||
// JobLeadSyncStatus is the resolver for the jobLeadSyncStatus field.
|
||||
func (r *queryResolver) JobLeadSyncStatus(ctx context.Context) (*model.JobLeadSyncStatus, error) {
|
||||
if r.Store.JobLeads == nil {
|
||||
return &model.JobLeadSyncStatus{LastError: "job leads are not configured"}, nil
|
||||
}
|
||||
status := r.Store.JobLeads.Status()
|
||||
return &model.JobLeadSyncStatus{Running: status.Running, LastRunAt: status.LastRunAt, LastError: status.LastError}, nil
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"adam-french.co.uk/backend/models"
|
||||
)
|
||||
|
||||
// setLeadState moves a lead from one state to another and returns it. It
|
||||
// lives here, not in job_lead.resolvers.go, because gqlgen moves anything in
|
||||
// a resolvers file that is not a resolver to the bottom on regeneration.
|
||||
//
|
||||
// The move is refused unless the lead is in `from`, which is what stops a
|
||||
// promoted lead being dismissed or restored: its application exists, and
|
||||
// flipping the lead would only make the inbox disagree with the tracker.
|
||||
func (r *mutationResolver) setLeadState(id int, from, to string) (*models.JobLead, error) {
|
||||
var lead models.JobLead
|
||||
if err := r.Store.DB.First(&lead, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if lead.State == to {
|
||||
return &lead, nil
|
||||
}
|
||||
if lead.State != from {
|
||||
return nil, fmt.Errorf("a %s lead cannot be made %s", lead.State, to)
|
||||
}
|
||||
if err := r.Store.DB.Model(&lead).Update("state", to).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &lead, nil
|
||||
}
|
||||
@@ -48,6 +48,15 @@ type CreateJobApplicationInput struct {
|
||||
Description *string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
type CreateJobSourceInput struct {
|
||||
Kind string `json:"kind"`
|
||||
Label string `json:"label"`
|
||||
Token *string `json:"token,omitempty"`
|
||||
Query *string `json:"query,omitempty"`
|
||||
Location *string `json:"location,omitempty"`
|
||||
Enabled *bool `json:"enabled,omitempty"`
|
||||
}
|
||||
|
||||
type CreatePlaceInput struct {
|
||||
Title string `json:"title"`
|
||||
Location *string `json:"location,omitempty"`
|
||||
@@ -78,6 +87,12 @@ type GiteaFeedItem struct {
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
type JobLeadSyncStatus struct {
|
||||
Running bool `json:"running"`
|
||||
LastRunAt *time.Time `json:"lastRunAt,omitempty"`
|
||||
LastError string `json:"lastError"`
|
||||
}
|
||||
|
||||
type LoginInput struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -149,6 +164,23 @@ type UpdateJobApplicationInput struct {
|
||||
Description *string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateJobSearchProfileInput struct {
|
||||
Profile *string `json:"profile,omitempty"`
|
||||
IncludeKeywords *string `json:"includeKeywords,omitempty"`
|
||||
ExcludeKeywords *string `json:"excludeKeywords,omitempty"`
|
||||
Locations *string `json:"locations,omitempty"`
|
||||
MinScore *int `json:"minScore,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateJobSourceInput struct {
|
||||
Kind *string `json:"kind,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
Token *string `json:"token,omitempty"`
|
||||
Query *string `json:"query,omitempty"`
|
||||
Location *string `json:"location,omitempty"`
|
||||
Enabled *bool `json:"enabled,omitempty"`
|
||||
}
|
||||
|
||||
type UpdatePlaceInput struct {
|
||||
Title *string `json:"title,omitempty"`
|
||||
Location *string `json:"location,omitempty"`
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# Job application tracker. Rows come from these mutations, automatically from
|
||||
# the email sync pipeline (backend/services/email_sync.go), or from the browser
|
||||
# capture userscript (backend/handlers/handle_job_capture.go). These are
|
||||
# private data, so the queries here are @admin as well as the mutations.
|
||||
# the email sync pipeline (backend/services/email_sync.go), from the browser
|
||||
# capture userscript (backend/handlers/handle_job_capture.go), or from
|
||||
# promoting a lead (job_lead.graphql). These are private data, so the queries
|
||||
# here are @admin as well as the mutations.
|
||||
#
|
||||
# description is the captured posting text. It can run to tens of kilobytes,
|
||||
# so the tracker's list query leaves it out and asks for it per row.
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
# Job leads: postings found automatically, as opposed to applications being
|
||||
# tracked (job_application.graphql). The fetcher in
|
||||
# backend/services/job_leads.go polls each JobSource, files what it finds as
|
||||
# JobLead rows and has Claude score them against the JobSearchProfile. A lead
|
||||
# reaches the tracker only when it is promoted from the leads page.
|
||||
#
|
||||
# All of it is private, so every field here is @admin, queries included.
|
||||
|
||||
# One place to poll. `kind` is one of greenhouse, lever, ashby (a company's
|
||||
# board: `token` is its slug and `label` the company name) or adzuna, reed (a
|
||||
# keyword search: `query` and `location`, with `label` only a display name).
|
||||
# It is a String rather than an enum because the resolver validates it and
|
||||
# the list is the fetcher's to extend (services/job_sources.go).
|
||||
#
|
||||
# The last* fields are written by the fetcher, never by a mutation.
|
||||
type JobSource {
|
||||
id: ID!
|
||||
createdAt: Time!
|
||||
updatedAt: Time!
|
||||
kind: String!
|
||||
label: String!
|
||||
token: String!
|
||||
query: String!
|
||||
location: String!
|
||||
enabled: Boolean!
|
||||
lastFetchedAt: Time
|
||||
lastCount: Int!
|
||||
lastError: String!
|
||||
}
|
||||
|
||||
input CreateJobSourceInput {
|
||||
kind: String!
|
||||
label: String!
|
||||
token: String
|
||||
query: String
|
||||
location: String
|
||||
enabled: Boolean
|
||||
}
|
||||
|
||||
input UpdateJobSourceInput {
|
||||
kind: String
|
||||
label: String
|
||||
token: String
|
||||
query: String
|
||||
location: String
|
||||
enabled: Boolean
|
||||
}
|
||||
|
||||
# description is the posting's full text, tens of kilobytes on some boards,
|
||||
# so the list query on the leads page leaves it out and asks per row — the
|
||||
# same arrangement as JobApplication.description.
|
||||
#
|
||||
# state is new, dismissed or promoted. score (0-100) and scoreReasons are
|
||||
# null until Claude has scored the lead, which only happens to matched ones.
|
||||
type JobLead {
|
||||
id: ID!
|
||||
createdAt: Time!
|
||||
sourceKind: String!
|
||||
jobTitle: String!
|
||||
company: String!
|
||||
location: String!
|
||||
url: String!
|
||||
description: String!
|
||||
postedAt: Time
|
||||
lastSeenAt: Time!
|
||||
matched: Boolean!
|
||||
state: String!
|
||||
score: Int
|
||||
scoreReasons: String
|
||||
jobAppId: ID
|
||||
}
|
||||
|
||||
# The single row a lead is judged against. profile is free text sent to
|
||||
# Claude with each posting; the three keyword lists hold one entry per line
|
||||
# and drive the pre-filter; minScore is the inbox's display threshold.
|
||||
type JobSearchProfile {
|
||||
updatedAt: Time!
|
||||
profile: String!
|
||||
includeKeywords: String!
|
||||
excludeKeywords: String!
|
||||
locations: String!
|
||||
minScore: Int!
|
||||
}
|
||||
|
||||
input UpdateJobSearchProfileInput {
|
||||
profile: String
|
||||
includeKeywords: String
|
||||
excludeKeywords: String
|
||||
locations: String
|
||||
minScore: Int
|
||||
}
|
||||
|
||||
# lastRunAt and lastError describe the most recent run in this backend
|
||||
# process; both reset when it restarts.
|
||||
type JobLeadSyncStatus {
|
||||
running: Boolean!
|
||||
lastRunAt: Time
|
||||
lastError: String!
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
jobSources: [JobSource!]! @admin
|
||||
# state filters to one of new, dismissed, promoted; omitted returns all.
|
||||
# Leads that failed the pre-filter are left out unless includeUnmatched.
|
||||
jobLeads(state: String, includeUnmatched: Boolean): [JobLead!]! @admin
|
||||
jobLead(id: ID!): JobLead @admin
|
||||
jobSearchProfile: JobSearchProfile! @admin
|
||||
jobLeadSyncStatus: JobLeadSyncStatus! @admin
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createJobSource(input: CreateJobSourceInput!): JobSource! @admin
|
||||
updateJobSource(id: ID!, input: UpdateJobSourceInput!): JobSource! @admin
|
||||
# Errors on an id that does not exist, like the other deletes; the Boolean
|
||||
# is only ever true. The source's leads are kept.
|
||||
deleteJobSource(id: ID!): Boolean! @admin
|
||||
|
||||
dismissJobLead(id: ID!): JobLead! @admin
|
||||
# Puts a dismissed lead back in the inbox. A promoted lead cannot be
|
||||
# restored: its application exists, and is managed on the tracker.
|
||||
restoreJobLead(id: ID!): JobLead! @admin
|
||||
# Adds the lead to the tracker as a saved application — or, if the posting
|
||||
# is already tracked, links to that row instead of making a second — and
|
||||
# returns the lead, now promoted, with jobAppId set.
|
||||
promoteJobLead(id: ID!): JobLead! @admin
|
||||
|
||||
updateJobSearchProfile(input: UpdateJobSearchProfileInput!): JobSearchProfile! @admin
|
||||
|
||||
# Starts a fetch-and-score run in the background and returns at once: true
|
||||
# if it started, false if one was already running. Poll jobLeadSyncStatus
|
||||
# to see it finish.
|
||||
runJobLeadSync: Boolean! @admin
|
||||
}
|
||||
Reference in New Issue
Block a user