Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #93 from fengmk2/sync-30m
Browse files Browse the repository at this point in the history
try to sync every 30 minutes
  • Loading branch information
dead-horse committed Dec 16, 2013
2 parents 51a35b4 + a40e297 commit 5c466a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var config = {
},
syncByInstall: true,
backupFilePrefix: '/cnpm/backup/', // backup filepath prefix
syncModel: 'all', // null, 'all', 'exist'
syncModel: 'none', // 'none', 'all', 'exist'
syncConcurrency: 1,
};

Expand Down
12 changes: 5 additions & 7 deletions sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@ Total.updateSyncStatus(0, utility.noop);
var syncing = false;

function handleSync() {
var now = new Date();
var hour = now.getHours();
debug('hour: %s, syncing: %s', hour, syncing);
// start sync at 2 a.m every day
if (hour === 2 && !syncing) {
debug('mode: %s, syncing: %s', config.syncModel, syncing);
// check sync every one 30 minutes
if (!syncing) {
syncing = true;
debug('start syncing');
sync(function (err, data) {
if (config.debug) {
console.log(err, data);
} else {
sendMailToAdmin(err, data, now);
sendMailToAdmin(err, data, new Date());
}
syncing = false;
});
Expand All @@ -60,7 +58,7 @@ function handleSync() {

if (sync) {
handleSync();
setInterval(handleSync, ms('1h'));
setInterval(handleSync, ms('30m'));
}

function sendMailToAdmin(err, result, syncTime) {
Expand Down

0 comments on commit 5c466a7

Please sign in to comment.