diff options
author | Jochen Topf <jochen@topf.org> | 2014-10-02 09:22:49 +0200 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2014-10-02 09:22:49 +0200 |
commit | faaa6560e74dab0e47245e42becc9a261873117b (patch) | |
tree | bb2361db86ccd2519aed808d524e225ad77206ef /sources/projects | |
parent | 957ee90110ecaad81129a27ca144e8940853a6f0 (diff) | |
download | taginfo-faaa6560e74dab0e47245e42becc9a261873117b.tar taginfo-faaa6560e74dab0e47245e42becc9a261873117b.tar.gz |
Make projects import script more robust.
Diffstat (limited to 'sources/projects')
-rwxr-xr-x | sources/projects/import.rb | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/sources/projects/import.rb b/sources/projects/import.rb index f128281..46ebc60 100755 --- a/sources/projects/import.rb +++ b/sources/projects/import.rb @@ -54,23 +54,33 @@ projects.each do |id, url| http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end - request = Net::HTTP::Get.new(uri.request_uri) - response = http.request(request) begin - last_modified = Time.parse(response['Last-Modified'] || response['Date']).utc.iso8601 + request = Net::HTTP::Get.new(uri.request_uri) + response = http.request(request) + begin + last_modified = Time.parse(response['Last-Modified'] || response['Date']).utc.iso8601 + rescue + last_modified = Time.now.utc + end + db.execute("INSERT INTO projects (id, json_url, last_modified, fetch_date, fetch_status, fetch_json, status, data_updated) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", + id, + url, + last_modified, + Time.now.utc.iso8601, + response.code, + response.body, + (response.code == '200' ? 'OK' : 'FETCH ERROR'), + last_modified + ); rescue - last_modified = Time.now.utc + db.execute("INSERT INTO projects (id, json_url, fetch_date, fetch_status, status) VALUES (?, ?, ?, ?, ?)", + id, + url, + Time.now.utc.iso8601, + 500, + 'FETCH ERROR' + ); end - db.execute("INSERT INTO projects (id, json_url, last_modified, fetch_date, fetch_status, fetch_json, status, data_updated) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", - id, - url, - last_modified, - Time.now.utc.iso8601, - response.code, - response.body, - (response.code == '200' ? 'OK' : 'FETCH ERROR'), - last_modified - ); end |