-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Periodic refresh process for project entries
This will attempt to refresh the project information, first using the stored etag to check the latest update on GitHub. ref: #74
- Loading branch information
Showing
4 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'ghtorrent/api_client' | ||
require 'ghtorrent/settings' | ||
require 'ghtorrent/retriever' | ||
|
||
module GHTorrent | ||
module Refresher | ||
|
||
def refresh_repo(owner, repo, db_entry) | ||
|
||
return db_entry if Time.now.to_i - db_entry[:updated_at].to_i > 3600 * 24 | ||
|
||
etag = db_entry[:etag] | ||
url = ghurl "repos/#{owner}/#{repo}" | ||
|
||
if last_updated(url, etag).to_i > db_entry[:updated_at].to_i | ||
fresh_repo = retrieve_repo(owner, repo, true) | ||
|
||
unless fresh_repo.nil? | ||
db.from(:projects). | ||
where(:id => db_entry[:id]). | ||
update(:etag => fresh_repo['etag']) | ||
end | ||
|
||
return db[:projects].first(:id => db_entry[:id]) | ||
end | ||
|
||
db_entry | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters