RetroPie-Setupという既存のシェルベースのフレームワークにフックするWebベースのツールを作成しています。NodeJS複数のexecFile呼び出しをキューに入れる
これらは、/RetroPie-Setup/retropie_packages.shというシェルスクリプトがあり、インストール、依存関係の取得、または異なるプログラムのコンパイルに使用できます。
1つの問題はpackages.shが特定の瞬間に複数回実行されるべきではないということです。そのため、一度に1つずつ実行されるキューをセットアップする必要があります。
複数の実行を防ぐためにpromise-queueを使用することはできますが、execFileを実行するたびにキュー内の場所に移動する代わりにすぐにコマンドを実行することになります。
downloadTest.sh
(固有の名前を持つ10Mバイトのファイルをダウンロードします):
filename=test$(date +%H%M%S).db
wget -O ${filename} speedtest.ftp.otenet.gr/files/test10Mb.db
rm ${filename}
ノードコード:
const Queue = require('promise-queue')
const { spawn,execFile } = require('child_process');
var maxConcurrent = 1;
var maxQueue = Infinity;
var que = new Queue(maxConcurrent, maxQueue);
var testFunct = function(file)
{
var promise = new Promise((reject,resolve) => {
execFile(file,function(error, stdout, stderr) {
console.log('Finished executing');
if(error)
{
reject();
} else
{
resolve(stdout);
}
});
})
return promise;
}
var test1 = testFunct('/home/pi/downloadTest.sh')
var test2 = testFunct('/home/pi/downloadTest.sh')
var test3 = testFunct('/home/pi/downloadTest.sh')
que.add(test1);
que.add(test2);
que.add(test3);