Итак, у меня есть сервер, который прослушивает запросы RabbitMQ:
console.log(' [*] Waiting for messages in %s. To exit press CTRL+C', q);
channel.consume(q, async function reply(msg) {
const mongodbUserId = msg.content.toString();
console.log(' [x] Received %s', mongodbUserId);
await exec('./new_user_run_athena.sh ' + mongodbUserId, function(
error,
stdout,
stderr
) {
console.log('Running Athena...');
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
console.log(
' Finished running Athena for mongodbUserId=%s',
mongodbUserId
);
channel.sendToQueue(
msg.properties.replyTo,
new Buffer(mongodbUserId),
{ correlationId: msg.properties.correlationId }
);
channel.ack(msg);
});
Проблема в том, что вызов await при выполнении сценария оболочки new_user_run_athena.sh
происходит после того, как я распечатал Finished running Athena for mongodbUserId
. Вы можете увидеть это в журнале консоли:
[*] Waiting for messages in run_athena_for_new_user_queue. To exit press CTRL+C
[x] Received 5aa96f36ed4f68154f3f2143
Finished running Athena for mongodbUserId=5aa96f36ed4f68154f3f2143
Running Athena...
stdout:
stderr:
Можно ли даже использовать синтаксис async await при выполнении сценария оболочки?