openings 0.1.50 → 0.1.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/crawler.ts +38 -11
- package/src/local-jobs.ts +2 -0
- package/src/runtime.ts +11 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
package/src/crawler.ts
CHANGED
|
@@ -22,6 +22,11 @@ interface CrawlerOptions {
|
|
|
22
22
|
describe?(source: Company, job: Job): Promise<string>;
|
|
23
23
|
/** Only roles open to these countries, posted in the last 30 days, get a description fetch. Empty: none do. */
|
|
24
24
|
describeCountries?: string[];
|
|
25
|
+
/** How many descriptions one source may be asked for in a run, and how long that may take. The nightly crawl
|
|
26
|
+
* keeps both small so no employer holds up the pass; the description catch-up raises them to reach an employer
|
|
27
|
+
* whose backlog is in the thousands, which 150 a night would never finish. */
|
|
28
|
+
describeLimit?: number;
|
|
29
|
+
describeBudgetMs?: number;
|
|
25
30
|
pacingNow?: () => number;
|
|
26
31
|
pacingSleep?: (delayMs: number) => Promise<void>;
|
|
27
32
|
now?: () => Date;
|
|
@@ -45,26 +50,47 @@ export function createCrawler(options: CrawlerOptions): Crawler {
|
|
|
45
50
|
const pacingSleep = options.pacingSleep ?? ((delayMs: number) => new Promise<void>((resolve) => setTimeout(resolve, delayMs)));
|
|
46
51
|
let previousStart: number | undefined;
|
|
47
52
|
let pacingGate = Promise.resolve();
|
|
48
|
-
|
|
53
|
+
/** Ordered, because the budget below is spent in this order: the first country named is served first. */
|
|
54
|
+
const describeOrder = options.describeCountries ?? [];
|
|
55
|
+
const describeCountries = new Set(describeOrder);
|
|
56
|
+
/** Where a job sits in the country priority; lower is sooner. Jobs outside the list are never fetched. */
|
|
57
|
+
function describeRank(job: Job): number {
|
|
58
|
+
let best = describeOrder.length;
|
|
59
|
+
for (const code of job.eligibleCountries) {
|
|
60
|
+
const rank = describeOrder.indexOf(code);
|
|
61
|
+
if (rank >= 0 && rank < best) best = rank;
|
|
62
|
+
}
|
|
63
|
+
return best;
|
|
64
|
+
}
|
|
49
65
|
|
|
50
66
|
/** Required experience for every job: from its description, the last crawl's reading, or a paced detail fetch for recent roles in describeCountries. */
|
|
51
67
|
async function withExperience(source: Company, jobs: Job[], previous: Job[] | undefined): Promise<Job[]> {
|
|
52
68
|
const known = new Map((previous ?? []).map(normalizeJobExperience).filter((job) => job.experienceVersion === EXPERIENCE_VERSION && job.experience !== undefined).map((job) => [job.id, job]));
|
|
53
69
|
const since = now().getTime() - 30 * 86_400_000;
|
|
54
|
-
const deadline = Date.now() + DESCRIBE_BUDGET_MS;
|
|
55
|
-
let budget = DESCRIBE_LIMIT;
|
|
56
70
|
const out: Job[] = [];
|
|
71
|
+
const pending: number[] = [];
|
|
57
72
|
for (const job of jobs) {
|
|
58
73
|
if (job.description.trim() || job.experienceVersion === EXPERIENCE_VERSION) out.push(normalizeJobExperience(job));
|
|
59
74
|
else if (known.has(job.id)) out.push({ ...job, description: known.get(job.id)!.description, experience: known.get(job.id)!.experience, experienceVersion: EXPERIENCE_VERSION });
|
|
60
|
-
else
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
else {
|
|
76
|
+
if (options.describe && describeRank(job) < describeOrder.length && Date.parse(job.updatedAt ?? "") >= since) pending.push(out.length);
|
|
77
|
+
out.push(normalizeJobExperience(job));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// The budget is small and shared, so it is spent by country priority rather than in whatever order the board
|
|
81
|
+
// listed its jobs. Without this, an employer with 4 India roles among 11,581 American ones never reads the four.
|
|
82
|
+
// Ties keep the board's own order, which is newest first on every provider that dates its postings.
|
|
83
|
+
pending.sort((left, right) => describeRank(jobs[left]!) - describeRank(jobs[right]!) || left - right);
|
|
84
|
+
const deadline = Date.now() + (options.describeBudgetMs ?? DESCRIBE_BUDGET_MS);
|
|
85
|
+
let budget = options.describeLimit ?? DESCRIBE_LIMIT;
|
|
86
|
+
for (const index of pending) {
|
|
87
|
+
if (budget <= 0 || Date.now() >= deadline) break;
|
|
88
|
+
budget -= 1;
|
|
89
|
+
try {
|
|
90
|
+
if (options.workdayPageDelayMs) await pacingSleep(options.workdayPageDelayMs);
|
|
91
|
+
const description = await options.describe!(source, jobs[index]!);
|
|
92
|
+
out[index] = normalizeJobExperience({ ...jobs[index]!, description });
|
|
93
|
+
} catch { /* unread; the next crawl tries again */ }
|
|
68
94
|
}
|
|
69
95
|
return out;
|
|
70
96
|
}
|
|
@@ -170,6 +196,7 @@ export function createCrawler(options: CrawlerOptions): Crawler {
|
|
|
170
196
|
}
|
|
171
197
|
|
|
172
198
|
// ponytail: per-source caps keep one crawl bounded; a big backlog (first run) drains over a few nights.
|
|
199
|
+
/** Defaults for the nightly crawl, where the point is to keep every source moving rather than finish any one. */
|
|
173
200
|
const DESCRIBE_LIMIT = 150;
|
|
174
201
|
const DESCRIBE_BUDGET_MS = 180_000;
|
|
175
202
|
|
package/src/local-jobs.ts
CHANGED
|
@@ -17,6 +17,8 @@ interface LocalJobsOptions {
|
|
|
17
17
|
workdayCountries?: string[];
|
|
18
18
|
describe?(source: Company, job: Job): Promise<string>;
|
|
19
19
|
describeCountries?: string[];
|
|
20
|
+
describeLimit?: number;
|
|
21
|
+
describeBudgetMs?: number;
|
|
20
22
|
now?: () => Date;
|
|
21
23
|
onCrawled?(source: Company, partition: JobPartition): void | Promise<void>;
|
|
22
24
|
}
|
package/src/runtime.ts
CHANGED
|
@@ -37,6 +37,9 @@ export function createRuntime(options: { dataDir?: string; concurrency?: number;
|
|
|
37
37
|
// Server crawls set OPENINGS_DESCRIBE_COUNTRIES (IN) to read required experience from Workday detail pages; installs skip the extra requests.
|
|
38
38
|
describe: (source, job) => fetchJobDescription(source, job, globalThis.fetch),
|
|
39
39
|
describeCountries: (process.env.OPENINGS_DESCRIBE_COUNTRIES ?? "").split(",").map((code) => code.trim().toUpperCase()).filter((code) => /^[A-Z]{2}$/.test(code)),
|
|
40
|
+
// The description catch-up pass raises these; unset, the nightly crawl keeps the crawler's own small defaults.
|
|
41
|
+
describeLimit: positiveEnv("OPENINGS_DESCRIBE_LIMIT"),
|
|
42
|
+
describeBudgetMs: positiveEnv("OPENINGS_DESCRIBE_BUDGET_MS"),
|
|
40
43
|
onCrawled,
|
|
41
44
|
});
|
|
42
45
|
const recommender = createJobRecommender({ sources: companies, store, crawl: local.crawl });
|
|
@@ -96,3 +99,11 @@ export function createHostedRuntime(options: { sources: Company[]; store: Snapsh
|
|
|
96
99
|
prepareJobSearch: preparation.prepare, getJobCoverage: coverage.getCoverage, recommend: recommender.recommend, analyzeJobFit: analyzer.analyze, optimizeResume: optimizer.optimize,
|
|
97
100
|
};
|
|
98
101
|
}
|
|
102
|
+
|
|
103
|
+
/** A positive whole number from the environment, or undefined when unset or nonsense. */
|
|
104
|
+
function positiveEnv(name: string): number | undefined {
|
|
105
|
+
const raw = process.env[name];
|
|
106
|
+
if (raw === undefined) return undefined;
|
|
107
|
+
const value = Number(raw);
|
|
108
|
+
return Number.isInteger(value) && value > 0 ? value : undefined;
|
|
109
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.52";
|