Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions actions/tops.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ exports.getTopTrackMembers = {
outputExample: {},
version: 'v2',
transaction: 'read',
cacheLifetime: 1000 * 60 * 60 * 24,
databases: ['topcoder_dw', 'tcs_dw', 'tcs_catalog'],
run: function (api, connection, next) {
api.log('Execute getTopTrackMembers#run', 'debug');
Expand All @@ -526,8 +527,7 @@ exports.getTopTrackMembers = {
dbConnectionMap = connection.dbConnectionMap,
result = {},
error,
sqlParams = {},
isNoPaging;
sqlParams = {};
if (!dbConnectionMap) {
helper.handleNoConnection(api, connection, next);
return;
Expand All @@ -549,8 +549,7 @@ exports.getTopTrackMembers = {
}
if (pageIndex === -1) {
pageIndex = 1;
pageSize = MAX_INT; // No paging, show all.
isNoPaging = true;
pageSize = MAX_PAGE_SIZE; // No paging, show max allowed.
}
// Retrieves total number of top members for the given track.
api.dataAccess.executeQuery('get_top_members_' + trackType + '_count', sqlParams, dbConnectionMap, cb);
Expand All @@ -559,10 +558,9 @@ exports.getTopTrackMembers = {
cb(new Error('no rows returned from get_top_members_' + trackType + '_count'));
return;
}
var total = rows[0].count;
result.total = total;
result.total = rows[0].count;
result.pageIndex = pageIndex;
result.pageSize = isNoPaging ? total : pageSize;
result.pageSize = pageSize;
result.data = [];
sqlParams.firstRowIndex = (pageIndex - 1) * pageSize;
sqlParams.pageSize = pageSize;
Expand Down
2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# nohup node ~/tc-api/node_modules/.bin/actionHero start 2>&1 &
#forever start -d -v -a -l "${DIR}/log/forever.log" "${DIR}/node_modules/actionhero/bin/actionhero" start
forever start -d -a -l "${DIR}/log/forever.log" "${DIR}/node_modules/actionhero/bin/actionhero" startCluster --workers=2
forever start -d -a -l "${DIR}/log/forever.log" "${DIR}/node_modules/actionhero/bin/actionhero" startCluster --workers=10
89 changes: 79 additions & 10 deletions workers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,90 @@
ACTION=$1
SIGNAL=""

pid=$(ps ax | grep startCluster | grep -v grep | xargs | cut -f1 -d' ')
if [ "$pid" == "" ]; then
echo "No cluster master process found."
exit
fi

function workers_ps {
ps_out=$(ps ax | grep -- "actionhero start$" | grep -v grep)
IFS='
'
IFS=${IFS:0:1}
workers=( $ps_out )
}

workers_ps

wpids=()
for worker in "${workers[@]}"
do
wpids+=("$(echo -e "${worker}" | xargs | cut -f1 -d' ')")
done


if [ "$ACTION" == "reload" ]; then
SIGNAL="HUP"
elif [ "$ACTION" == "add" ]; then
SIGNAL="TTIN"
elif [ "$ACTION" == "rm" ]; then
SIGNAL="TTOU"
fi
elif [ "$ACTION" == "kill" ]; then
for wpid in "${wpids[@]}"
do
kill -9 $wpid # kill the workers and let master restart
done
exit
elif [ "$ACTION" == "recycle" ]; then
numWorkers=${#wpids[@]}
echo "Start Recycle, Workers Running: ${#workers[@]}"

for wpid in "${wpids[@]}"
do
kill -TTIN $pid # add one
sleep 1
done

if [ "$SIGNAL" == "" ]; then
echo "Usage: workers.sh [reload|add|rm]"
declare -i sleepTime
sleepTime=$numWorkers
sleep $sleepTime

workers_ps
echo "Max Workers Running: ${#workers[@]}"

# signal recycle of all
kill -HUP $pid

sleepTime=$numWorkers*2
sleep $sleepTime

for wpid in "${wpids[@]}"
do
kill -TTOU $pid # remove one
sleep 1
done

sleepTime=$numWorkers/2
sleep $sleepTime

workers_ps
echo "End Recycle, Workers Running: ${#workers[@]}"
exit
elif [ "$ACTION" == "ls" ]; then
for worker in "${workers[@]}"
do
echo -e "${worker}" | xargs | cut -f1,4 -d' '
done
echo "Count: ${#wpids[@]}"
exit
elif [ "$ACTION" == "count" ]; then
echo "${#wpids[@]}"
exit
else
pid=$(ps ax | grep startCluster | grep -v grep | xargs | cut -f1 -d' ')
if [ "$pid" == "" ]; then echo "No cluster master process found."
else
kill -$SIGNAL $pid
echo "Signal $SIGNAL sent to process: $pid"
fi
fi
echo "Usage: workers.sh [reload|recycle|add|rm|ls|count]"
exit
fi

kill -$SIGNAL $pid
echo "Signal $SIGNAL sent to process: $pid"