1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { execute_action_and_record } from '../../task_executor.js';
|
||||
import { map_limit, sleep_ms } from '../flow_utils.js';
|
||||
import { sleep_ms } from '../flow_utils.js';
|
||||
import { amazon_product, amazon_search_item, amazon_review } from '../../../models/index.js';
|
||||
import { safe_json_stringify } from '../../json_utils.js';
|
||||
import { close_browser } from '../../puppeteer/puppeteer_runner.js';
|
||||
@@ -51,14 +51,15 @@ async function persist_detail(detail_res_raw) {
|
||||
return;
|
||||
}
|
||||
|
||||
const sku_is_object = detail_res && detail_res.sku && typeof detail_res.sku === 'object' && !Array.isArray(detail_res.sku);
|
||||
|
||||
await amazon_product.upsert({
|
||||
asin,
|
||||
url: detail_res.url || '',
|
||||
title: detail_res.title || null,
|
||||
price: detail_res.price || null,
|
||||
sku: detail_res.sku || null,
|
||||
sku_color: detail_res.sku_color || null,
|
||||
sku_size: detail_res.sku_size || null,
|
||||
sku: sku_is_object ? null : (detail_res.sku || null),
|
||||
sku_json: sku_is_object ? detail_res.sku : null,
|
||||
brand_line: detail_res.brand_line || null,
|
||||
brand_store_url: detail_res.brand_store_url || null,
|
||||
ac_badge: detail_res.ac_badge || null,
|
||||
@@ -69,10 +70,10 @@ async function persist_detail(detail_res_raw) {
|
||||
rating_stars: detail_res.rating_stars || null,
|
||||
review_count_text: detail_res.review_count_text || null,
|
||||
main_image: detail_res.main_image || null,
|
||||
images_json: safe_json_stringify(detail_res.images || []),
|
||||
bullets_json: safe_json_stringify(detail_res.bullets || []),
|
||||
product_info_json: safe_json_stringify(detail_res.product_info || {}),
|
||||
detail_extra_lines_json: safe_json_stringify(detail_res.detail_extra_lines || [])
|
||||
images_json: Array.isArray(detail_res.images) ? detail_res.images : null,
|
||||
bullets_json: Array.isArray(detail_res.bullets) ? detail_res.bullets : null,
|
||||
product_info_json: detail_res.product_info && typeof detail_res.product_info === 'object' ? detail_res.product_info : null,
|
||||
detail_extra_lines_json: Array.isArray(detail_res.detail_extra_lines) ? detail_res.detail_extra_lines : null
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,3 @@
|
||||
export async function sleep_ms(ms) {
|
||||
await new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export async function map_limit(items, worker) {
|
||||
const list = Array.isArray(items) ? items : [];
|
||||
|
||||
const res = new Array(list.length);
|
||||
let idx = 0;
|
||||
|
||||
async function run_one() {
|
||||
while (idx < list.length) {
|
||||
const cur = idx;
|
||||
idx += 1;
|
||||
res[cur] = await worker(list[cur], cur);
|
||||
}
|
||||
}
|
||||
|
||||
const runners = [];
|
||||
for (let i = 0; i < list.length; i += 1) {
|
||||
runners.push(run_one());
|
||||
}
|
||||
|
||||
await Promise.all(runners);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -31,11 +31,9 @@ async function run_cron_task(task) {
|
||||
export async function start_all_cron_tasks() {
|
||||
for (const task of cron_task_list) {
|
||||
// const job = cron.schedule(task.cron_expression, async () => {
|
||||
try {
|
||||
|
||||
await run_cron_task(task);
|
||||
} catch (err) {
|
||||
// action 内部已记录 crawl_run_record;flow 内部 action 也会记录
|
||||
}
|
||||
|
||||
// });
|
||||
|
||||
// cron_jobs.push(job);
|
||||
|
||||
Reference in New Issue
Block a user