This repository has been archived by the owner on Jan 16, 2020. It is now read-only.
New scripts to fetch github data and update pluginsdb. #137
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d3a09f2
Added new scripts for pulling stats from github api.
aulvi 244a342
Cleaned up some formatting issues, removed etags handling and data va…
aulvi a3d6f55
Added logger.
aulvi 2a1adb0
Updated formatting per style guide.
aulvi c1e558d
Updated the code as instructed, cleaned up formatting and tightened t…
aulvi 5fac1e2
Added github data to the config-sample.json, updated getStats to send…
aulvi d2d0bb4
Removed an unnecessary map call, moved the setTimeout.
aulvi 773541a
Removed a comment.
aulvi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,59 @@ | |||
var db = require( "../lib/pluginsdb" ), | |||
service = require( "../lib/service" ), | |||
logger = require( "../lib/logger" ), | |||
iv, | |||
queue, | |||
ready, | |||
delay = 60*1000; | |||
|
|||
function update( err, plugin ) { | |||
if ( err ) { | |||
logger.log( err ); | |||
} else { | |||
db.updateRepoMeta( plugin.repo, plugin, function(err){ | |||
if ( err ) { | |||
logger.log( err ); | |||
} | |||
iv = setTimeout( processData, delay ); | |||
}); | |||
} | |||
} | |||
|
|||
function processData() { | |||
var repo, | |||
data = queue.shift(); | |||
|
|||
if ( !ready ) { | |||
clearTimeout( iv ); | |||
process.exit( 0 ); | |||
} else if ( !data ) { | |||
iv = setTimeout( init, delay ); | |||
} else if ( ready && data ) { | |||
repo = service.getRepoById( data.repo ); | |||
repo.getStats( data, update ); | |||
} | |||
} | |||
|
|||
function init() { | |||
db.getAllPlugins(function( err, plugins ) { | |||
if ( !err && plugins.length > 0 ) { | |||
queue = plugins; | |||
ready = true; | |||
processData(); | |||
} else { | |||
iv = setTimeout( init, delay ); | |||
} | |||
}); | |||
} | |||
|
|||
// Kick off | |||
init(); | |||
|
|||
// Let the current action finish, then stop processing and exit | |||
function shutdownHook() { | |||
logger.log( "Shutting down update-plugin-stats." ); | |||
ready = false; | |||
} | |||
|
|||
process.once( "SIGINT", shutdownHook ); | |||
process.once( "SIGTERM", shutdownHook ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cron jobs don't need shutdown hooks.