aboutsummaryrefslogtreecommitdiff
path: root/sources/projects
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2014-10-02 09:22:49 +0200
committerJochen Topf <jochen@topf.org>2014-10-02 09:22:49 +0200
commitfaaa6560e74dab0e47245e42becc9a261873117b (patch)
treebb2361db86ccd2519aed808d524e225ad77206ef /sources/projects
parent957ee90110ecaad81129a27ca144e8940853a6f0 (diff)
downloadtaginfo-faaa6560e74dab0e47245e42becc9a261873117b.tar
taginfo-faaa6560e74dab0e47245e42becc9a261873117b.tar.gz
Make projects import script more robust.
Diffstat (limited to 'sources/projects')
-rwxr-xr-xsources/projects/import.rb38
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