Skip to content

Commit

Permalink
modify update_db.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
d4n1elchen committed Feb 10, 2017
1 parent 17350d3 commit 22d0f93
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
File renamed without changes.
3 changes: 3 additions & 0 deletions backups/mongo-connector-cmd.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mongo-connector -m localhost:27017 -t localhost:9200 -d elastic2_doc_manager\
-a ccns -p CCNSccns\
--logfile $LOGDIR/mongo-connector.log --oplog-ts $LOGDIR/oplog.timestamp &
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "a crawler",
"main": "run.js",
"scripts": {
"start": "node run.js"
"start": "node run.js",
"updateDept": "node -e 'require(\"./update.js\").updateDeptList()'"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion run.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var update = require("./update.js");

update(false);
update.update(false);
8 changes: 6 additions & 2 deletions update.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function updateCourseList(dept) {
if (courses<0) {
yield new Error(dept_no+": timeout");
} else {
// console.log(dept_no+": "+courses.length);
console.log(dept_no+": "+courses.length);
if (courses.length > 0) {
var db = yield MongoClient.connect(url);
var collection = db.collection('courses');
Expand Down Expand Up @@ -106,4 +106,8 @@ function update(updateDept) {
go(gen.next());
}

module.exports = update
module.exports = {
update: update,
updateDeptList: updateDeptList,
updateCourseList: updateCourseList
}
17 changes: 1 addition & 16 deletions update_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,8 @@ BASEDIR=$(pwd)
LOGDIR=${1:-$BASEDIR/log}
LOGFILE=$LOGDIR/update.log

echo "Starting mongo-connector" | $BASEDIR/predate.sh >> $LOGFILE
mongo-connector -m localhost:27017 -t localhost:9200 -d elastic2_doc_manager\
-a ccns -p CCNSccns\
--logfile $LOGDIR/mongo-connector.log --oplog-ts $LOGDIR/oplog.timestamp &
MCPID=$!
echo "Mongo-connector started. PID=$MCPID" | $BASEDIR/predate.sh >> $LOGFILE

(time bash -c "cd $BASEDIR/pages && ./update_pages.sh | $BASEDIR/predate.sh >> $LOGFILE && cd ..") 2>&1 | $BASEDIR/predate.sh >> $LOGFILE
node run | $BASEDIR/predate.sh >> $LOGFILE

echo "Killing mongo-connector. PID=$MCPID" | $BASEDIR/predate.sh >> $LOGFILE
kill $MCPID 2>&1 | $BASEDIR/predate.sh >> $LOGFILE
if [ $PIPESTATUS -eq 0 ]; then
echo "All success." | $BASEDIR/predate.sh >> $LOGFILE
else
echo "Kill mongo-connector failed." | $BASEDIR/predate.sh >> $LOGFILE
fi

TOC=$((`date +%s`-TIC))
echo "Total excution time: $TOC" | $BASEDIR/predate.sh >> $LOGFILE
echo "Finished. Total excution time: $TOC" | $BASEDIR/predate.sh >> $LOGFILE

0 comments on commit 22d0f93

Please sign in to comment.