From 8d195a0d42984695a5a0cd10d08c7b8feacc7072 Mon Sep 17 00:00:00 2001 From: unwox Date: Sun, 15 Jun 2025 22:14:44 +0600 Subject: correctly handle fetching errors: skip troublesome shops --- bin/fetch.fnl | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'bin') diff --git a/bin/fetch.fnl b/bin/fetch.fnl index dd7c6c4..583b48a 100644 --- a/bin/fetch.fnl +++ b/bin/fetch.fnl @@ -195,18 +195,21 @@ FROM products;" [])) (must (luna.db.commit tx))) - (each [_ parser (pairs [batatcha yoceramics daochai gorkovchay ozchai suhexuan - ipuer artoftea clubcha chaekshop kolokolnikovchai - tea108 teaworkshop chaibez moychay])] - (local products (parser.products)) - (when (< 0 (# products)) - ;; replace with with-tx - (local tx (must (luna.db.begin db))) - (local (ok? err) (pcall store-products tx products)) - (must (luna.db.commit tx)) - (when (not ok?) - (print (string.format "Error fetching %s:\n%s" - parser.title err))))) +(each [_ parser (pairs [batatcha yoceramics daochai gorkovchay ozchai suhexuan + ipuer artoftea clubcha chaekshop kolokolnikovchai + tea108 teaworkshop chaibez moychay])] + (let [(ok? products) (pcall parser.products)] + (if (and ok? (< 0 (# products))) + (do + ;; replace with with-tx + (local tx (must (luna.db.begin db))) + (local (ok? err) (pcall store-products tx products)) + (must (luna.db.commit tx)) + (when (not ok?) + (print (string.format "Error storing %s:\n%s" + parser.title err)))) + (print (string.format "Error fetching %s:\n%s" + parser.title (or products "no products fetched")))))) (cache.clear db "page:") (populate-search-table db) -- cgit v1.2.3