0

My Code is getting stuck in this function. It goes into a chain of callbacks. Could someone please guide me through it?

router.get('/search',function(req, res, next){
    //Check/Convert the selected query to MPEG
    //Color_Analysis.py -d path/to/query -c 1 :- outputs a file with 150 lines & Avg.py
    //back.py -d path/to/query :-  will generate file with 8/10 lines.
    //Audio.py index_number_of_query :- will output a vector of weights 
    //Combine all outputs and display the frame.
    console.log("I entered-1 :(");
    queryPath = "/home/akshay/Desktop/576_Pro/MediaServer/public/dataset/query";
    queryFolder = queryPath+'/'+req.param('query'); 
    console.log(queryFolder);
    console.log("I entered-2 :(");

    // exec("ba(sh ~/Desktop/576_Pro/MediaServer/public/run_project.sh",function(err, stdout, stderr){  
    console.log("I entered-3 :(");

    exec("bash ~/Desktop/576_Pro/MediaServer/public/run_project.sh "+queryFolder,function(error, stdout, stderr){
        if(error){
            console.log('Akshay');
            console.log('error'+error);
            return;
        } 

        console.log("Error "+stderr+"   stdout "+stdout);
        res.writeHead(302, {'Location': '/results'});
        res.end();

    });

I don't have any idea but I just want to know if my bash file isn't making the node.js callback. This is the run_project.sh bash file which is being included in the code above:

#!/bin/sh
echo "In Bash"
cd '/home/akshay/Desktop/576_Pro/MediaServer/public/python/'
echo "Convert query to mp4"
#./run_project2.sh $1
#python createpng.py -d $1 > supress.txt
echo "Converted to mp4"
echo "Started Color"
python color/Color_analysis.py -d $1 -c 1 > ../descriptors/color_temp.txt
python color/color_out.py ../descriptors/color_temp.txt > ../descriptors/color.txt
python color/color_result.py ../descriptors/color_temp.txt > ../descriptors/frame_info.txt
python color/color_graph.py ../descriptors/color_temp.txt > ../descriptors/graph_info.txt
echo "Finished Color"
# python color/color_check.py query_color.txt > color_out
echo "Started Audio"
python audio/Audio_Init.py
python audio/Audio.py $1 > ../descriptors/audio.txt
echo 'Finished Executing'
echo 'Started Motion'
python motion/back.py -d $1 > ../descriptors/video_desc_temp.txt
python motion/optical_check.py -d '/home/akshay/Desktop/576_Pro/MediaServer/public/descriptors/motion' -q ../descriptors/video_desc_temp.txt > ../descriptors/motion.txt 
echo 'Finished Video'

I have tested the bash script prior to integrating it in the node.js and have faced no issues regarding it. It runs pretty much fine except for the fact that it takes about 5 min for the fact that the python files executing above are pretty heavy and they take a lot of time. But other then that all seems to work pretty much ok.

No Name
  • 1
  • 1
  • I have tested the bash file from the cmd and it runs fine. But its pretty heavy and takes about 5 minutes. Could that be an issue? – No Name May 04 '15 at 10:56
  • It actually callbacks it about 5 to 6 times and runs for almost 15 minutes. But after 15-20 minutes it gives me output. But am not able to make it faster. It very very very slow :( – No Name May 04 '15 at 11:00
  • @Cristik exec command will run asynchronous so i think res.end statement will be executed before running exec statment – KlwntSingh May 04 '15 at 11:07
  • @Cristik yeah, sorry but are you sure that webserver container will abort it after certain period of time. – KlwntSingh May 04 '15 at 11:13
  • I just edited the question and also included by bash file. If it helps to find the issue. – No Name May 04 '15 at 11:20

1 Answers1

0

I do not know what the actual problem was. But I changed the bash script and divided it into three different bash scripts. Also I made it route against three different pages for completing the whole process and execute one bash script at each page. The node.js works perfectly fine now and I believe the problem must be the timeout.

No Name
  • 1
  • 1