-
-
Notifications
You must be signed in to change notification settings - Fork 126
Puppeteer improvements #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f88607b
44da995
64398ec
a6769d2
22036a0
37b1c99
5050e63
535bb3b
705818d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import FredyPipelineExecutioner from '../../FredyPipelineExecutioner.js'; | |
| import * as similarityCache from '../similarity-check/similarityCache.js'; | ||
| import { isRunning, markFinished, markRunning } from './run-state.js'; | ||
| import { sendToUsers } from '../sse/sse-broker.js'; | ||
| import * as puppeteerExtractor from '../extractor/puppeteerExtractor.js'; | ||
|
|
||
| /** | ||
| * Initializes the job execution service. | ||
|
|
@@ -94,7 +95,7 @@ export function initJobExecutionService({ providers, settings, intervalMs }) { | |
| * @param {{userId?: string, isAdmin?: boolean}} [context] - Who requested the run; determines job filtering. | ||
| * @returns {void} | ||
| */ | ||
| function runAll(respectWorkingHours = true, context = undefined) { | ||
| async function runAll(respectWorkingHours = true, context = undefined) { | ||
| if (settings.demoMode) return; | ||
| const now = Date.now(); | ||
| const withinHours = duringWorkingHoursOrNotSet(settings, now); | ||
|
|
@@ -103,15 +104,18 @@ export function initJobExecutionService({ providers, settings, intervalMs }) { | |
| return; | ||
| } | ||
| settings.lastRun = now; | ||
| jobStorage | ||
| const jobs = jobStorage | ||
| .getJobs() | ||
| .filter((job) => job.enabled) | ||
| .filter((job) => { | ||
| if (!context) return true; // startup/cron → all | ||
| if (context.isAdmin) return true; // admin → all | ||
| return context.userId ? job.userId === context.userId : false; // user → own | ||
| }) | ||
| .forEach((job) => executeJob(job)); | ||
| }); | ||
|
|
||
| for (const job of jobs) { | ||
| await executeJob(job); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -154,28 +158,36 @@ export function initJobExecutionService({ providers, settings, intervalMs }) { | |
| } catch (err) { | ||
| logger.warn('Failed to emit start status for job', job.id, err); | ||
| } | ||
| let browser; | ||
| try { | ||
| const jobProviders = job.provider.filter( | ||
| (p) => providers.find((loaded) => loaded.metaInformation.id === p.id) != null, | ||
| ); | ||
| const executions = jobProviders.map(async (prov) => { | ||
| const matchedProvider = providers.find((loaded) => loaded.metaInformation.id === prov.id); | ||
| matchedProvider.init(prov, job.blacklist); | ||
| await new FredyPipelineExecutioner( | ||
| matchedProvider.config, | ||
| job.notificationAdapter, | ||
| prov.id, | ||
| job.id, | ||
| similarityCache, | ||
| ).execute(); | ||
| }); | ||
| const results = await Promise.allSettled(executions); | ||
| for (const r of results) { | ||
| if (r.status === 'rejected') { | ||
| logger.error(r.reason); | ||
| for (const prov of jobProviders) { | ||
| try { | ||
| const matchedProvider = providers.find((loaded) => loaded.metaInformation.id === prov.id); | ||
| matchedProvider.init(prov, job.blacklist); | ||
|
|
||
| if (!browser && matchedProvider.config.getListings == null) { | ||
| browser = await puppeteerExtractor.launchBrowser(matchedProvider.config.url, {}); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| await new FredyPipelineExecutioner( | ||
| matchedProvider.config, | ||
| job.notificationAdapter, | ||
| prov.id, | ||
| job.id, | ||
| similarityCache, | ||
| browser, | ||
| ).execute(); | ||
| } catch (err) { | ||
| logger.error(err); | ||
| } | ||
| } | ||
| } finally { | ||
| if (browser) { | ||
| await puppeteerExtractor.closeBrowser(browser); | ||
| } | ||
| markFinished(job.id); | ||
| try { | ||
| bus.emit('jobs:status', { jobId: job.id, running: false }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be simplified:
options?.userDataDir