summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2025-06-15 22:14:44 +0600
committerunwox <me@unwox.com>2025-06-15 22:14:44 +0600
commit8d195a0d42984695a5a0cd10d08c7b8feacc7072 (patch)
tree9e5dcce01c4764cea527fd3bf95ebb118560ff28 /bin
parent3cf517f0d6165b20e5656b1829b19f951716783e (diff)
correctly handle fetching errors: skip troublesome shops
Diffstat (limited to 'bin')
-rw-r--r--bin/fetch.fnl27
1 files changed, 15 insertions, 12 deletions
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)