Give a company a by-hand reason and a date last checked, in migration 15
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0a1d3c67c7
commit
a466ea52b7
4 files changed
+120
-19
No files matched your search
@@ -644,6 +644,16 @@ STATUSES: tuple[str, ...] = get_args(Status)
|
||||
#: -1 mute, 0 neutral, 1 interested, 2 favourite (skips gates, floors the score).
|
||||
AFFINITY = range(-1, 3)
|
||||
|
||||
#: Why a company is on the list checked by hand. `unread` is a host the app
|
||||
#: could read and has no parser for yet, `robots` a site whose robots.txt
|
||||
#: disallows it, `blocked` one that answers a program with a challenge, `key`
|
||||
#: one whose API answers only with a key lifted from its own script, `group` a
|
||||
#: company that sits inside its owner's board, `gone` one whose site is dead,
|
||||
#: and `added` one put there by hand or by an import and not looked at. ''
|
||||
#: is none of these: the company is read, or is not a matter for the list.
|
||||
HandReason = Literal["", "unread", "robots", "blocked", "key", "group", "gone", "added"]
|
||||
HAND_REASONS: tuple[str, ...] = get_args(HandReason)
|
||||
|
||||
|
||||
# -------------------------------------------------------------- posting dates
|
||||
|
||||
@@ -924,6 +934,12 @@ class Company(Model):
|
||||
#: The name `ats` knows the company by, the `acme` of acme.teamtailor.com;
|
||||
#: "" where discovery found none. Kept for a host no parser reads yet.
|
||||
ats_slug: str = ""
|
||||
#: Why the company is read by hand, one of `HAND_REASONS`; "" when it is
|
||||
#: not on that list.
|
||||
hand_reason: str = ""
|
||||
#: When a person last looked at its careers page, an ISO timestamp; ""
|
||||
#: for never.
|
||||
checked_at: str = ""
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
+10
-1
@@ -107,6 +107,8 @@ CREATE TABLE IF NOT EXISTS role_tags (
|
||||
-- yet. country is an ISO code and city the head office's. ats_slug is the
|
||||
-- name that host knows the company by (the acme of acme.teamtailor.com),
|
||||
-- '' where its URL carries none, kept for the parser written later.
|
||||
-- hand_reason is why a person reads the careers page (models.HAND_REASONS),
|
||||
-- '' when nobody has to, and checked_at when one last did, '' for never.
|
||||
CREATE TABLE IF NOT EXISTS companies (
|
||||
key TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
@@ -119,7 +121,9 @@ CREATE TABLE IF NOT EXISTS companies (
|
||||
ats TEXT NOT NULL DEFAULT '',
|
||||
country TEXT NOT NULL DEFAULT '',
|
||||
city TEXT NOT NULL DEFAULT '',
|
||||
ats_slug TEXT NOT NULL DEFAULT ''
|
||||
ats_slug TEXT NOT NULL DEFAULT '',
|
||||
hand_reason TEXT NOT NULL DEFAULT '',
|
||||
checked_at TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
-- The targets desk's runner hands to plugins. newsdesk's shape, with its two
|
||||
@@ -423,6 +427,11 @@ ALTER TABLE agents DROP COLUMN intent;
|
||||
ALTER TABLE agents DROP COLUMN intent_key;
|
||||
ALTER TABLE agents DROP COLUMN intent_vec;
|
||||
ALTER TABLE scores ADD COLUMN prompt TEXT NOT NULL DEFAULT '';
|
||||
"""),
|
||||
(15, "companies.hand_reason and checked_at: the companies read by hand are a list "
|
||||
"with a reason and a date last looked at", """
|
||||
ALTER TABLE companies ADD COLUMN hand_reason TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE companies ADD COLUMN checked_at TEXT NOT NULL DEFAULT '';
|
||||
"""),
|
||||
)
|
||||
|
||||
|
||||
+24
-6
@@ -21,7 +21,7 @@ import numpy as np
|
||||
|
||||
from desk.models import Item
|
||||
from app.models import (
|
||||
AFFINITY, REMOTE, STATUSES, Agent, Application, ApplicationEvent, Candidate,
|
||||
AFFINITY, HAND_REASONS, REMOTE, STATUSES, Agent, Application, ApplicationEvent, Candidate,
|
||||
Company, Gate, Limits, Prompt, Role, RoleRow, ScoredRole, Subscription, Weights,
|
||||
check_prompts, company_key, country_of, excerpt, place_key, posted_at, posted_host,
|
||||
remote_of, title_key,
|
||||
@@ -94,7 +94,7 @@ _EXCERPT_SOURCE = "COALESCE(NULLIF(roles.summary, ''), roles.description)"
|
||||
_EXCERPT_RAW = 240
|
||||
|
||||
_COMPANY_FIELDS = ("name", "domain", "status", "careers_url", "notes", "ats", "country", "city",
|
||||
"ats_slug")
|
||||
"ats_slug", "hand_reason", "checked_at")
|
||||
|
||||
#: A company as the store serves it: the row and the asked-for agent's affinity.
|
||||
_COMPANY_SELECT = """SELECT c.*, COALESCE(ac.affinity, 0) AS affinity FROM companies c
|
||||
@@ -1162,18 +1162,22 @@ class Store:
|
||||
def add_company(self, name: str, *, key: str = "", domain: str = "",
|
||||
status: str = "researching", careers_url: str = "",
|
||||
notes: str = "", ats: str = "", country: str = "",
|
||||
city: str = "", ats_slug: str = "") -> Company:
|
||||
"""Raises ValueError on a key already taken."""
|
||||
city: str = "", ats_slug: str = "", hand_reason: str = "",
|
||||
checked_at: str = "") -> Company:
|
||||
"""Raises ValueError on a key already taken or a `hand_reason` outside
|
||||
`HAND_REASONS`."""
|
||||
name = name.strip()
|
||||
key = key or company_key(name)
|
||||
if not key:
|
||||
raise ValueError("a company needs a name")
|
||||
_check_hand_reason(hand_reason)
|
||||
try:
|
||||
with self.transaction() as conn:
|
||||
self._insert_company(conn, key, name, {
|
||||
"domain": domain, "status": status, "careers_url": careers_url,
|
||||
"notes": notes, "ats": ats, "country": country, "city": city,
|
||||
"ats_slug": ats_slug})
|
||||
"ats_slug": ats_slug, "hand_reason": hand_reason,
|
||||
"checked_at": checked_at})
|
||||
except sqlite3.IntegrityError as exc:
|
||||
raise ValueError(f"company {key!r} already exists") from exc
|
||||
return self._company(key)
|
||||
@@ -1237,6 +1241,8 @@ class Store:
|
||||
unknown = set(fields) - set(_COMPANY_FIELDS)
|
||||
if unknown:
|
||||
raise ValueError(f"not a company field: {', '.join(sorted(unknown))}")
|
||||
if "hand_reason" in fields:
|
||||
_check_hand_reason(fields["hand_reason"])
|
||||
if fields:
|
||||
sets = ", ".join(f"{f}=?" for f in fields)
|
||||
changed = self._write(f"UPDATE companies SET {sets}, updated_at=? WHERE key=?",
|
||||
@@ -1246,7 +1252,13 @@ class Store:
|
||||
return self._company(key)
|
||||
|
||||
def remove_company(self, key: str) -> bool:
|
||||
return self._write("DELETE FROM companies WHERE key=?", (key,)) > 0
|
||||
"""Delete the row and every agent's stance on it, in one transaction:
|
||||
`agent_companies` holds the key with no foreign key to hold it back, so
|
||||
a row left behind would give a company added again under the same name
|
||||
an affinity it never got. Roles and subscriptions are not touched."""
|
||||
with self.transaction() as conn:
|
||||
conn.execute("DELETE FROM agent_companies WHERE company_key=?", (key,))
|
||||
return conn.execute("DELETE FROM companies WHERE key=?", (key,)).rowcount > 0
|
||||
|
||||
def _company(self, key: str, agent_id: int | None = None) -> Company:
|
||||
found = self.company(key, agent_id)
|
||||
@@ -1541,6 +1553,12 @@ def _check_status(status: str) -> None:
|
||||
f"({', '.join(STATUSES)})")
|
||||
|
||||
|
||||
def _check_hand_reason(reason: Any) -> None:
|
||||
if reason not in HAND_REASONS:
|
||||
raise ValueError(f"hand_reason is one of {', '.join(repr(r) for r in HAND_REASONS)}, "
|
||||
f"not {reason!r}")
|
||||
|
||||
|
||||
def _check_affinity(affinity: Any) -> None:
|
||||
if isinstance(affinity, bool) or not isinstance(affinity, int) or affinity not in AFFINITY:
|
||||
raise ValueError(f"affinity is -1, 0, 1 or 2, not {affinity!r}")
|
||||
Reference in new issue
Block a user