diff options
| -rw-r--r-- | bin/fetch.fnl | 27 |
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) |
