【问题标题】:Why does Meteor restart every time a do a certain Meteor.call?为什么 Meteor 每次执行某个 Meteor.call 时都会重新启动?
【发布时间】:2018-12-23 16:16:09
【问题描述】:

(这个问题被标记为可能是重复的,但它不是(据我所知),因为另一个问题是关于如何写入本地磁盘,这不是我的问题。我可以写服务器磁盘没有问题,但是这样做会导致 Meteor 重新启动。)

我的客户端代码中有一个 Meteor.call(),它可以按预期工作,将 Google Cloud Text-to-Speech 文件保存到服务器并在客户端中创建指向声音文件的链接。但是,每次我调用 Meteor 时,Meteor 服务器都会在完成任务大约 2 秒后自行重启。这是客户端代码:

(client/main.js)
Meteor.call('get.tts.links', tempSoundPath, voice, currentForeign, 
currentExample, function(error, result) {
  if (error) {
    alert('Error');
  } else {
    Session.set("links", result);
    soundLink1 = 'tempsoundfiles/' + result[0] + ".mp3";
    if (!result[1]) soundLink2 = "";
    else soundLink2 = 'tempsoundfiles/' + result[1] + ".mp3";
  }
});

这是服务器代码的样子(对不起,冗长和冗余——我不是真正的程序员):

(server/main.js)
const textToSpeech = require('@google-cloud/text-to-speech');
....
....
'get.tts.links'(tempSoundPath, voice, currentForeign, currentExample) {
  var path = "";
  var soundFileId = "";
  var text1 = currentForeign;
  var text2 = currentExample;
  var fileId = makepass();

  const client = new textToSpeech.TextToSpeechClient();
  const request = {
    input: {
      text: text1
    },
    voice: {
      languageCode: "en-GB",
      ssmlGender: 'MALE'
    },
    audioConfig: {
      audioEncoding: 'MP3'
    },
  };
  client.synthesizeSpeech(request, (err, response) => {
    if (err) {
      console.error('ERROR:', err);
      return;
    }
    path = tempSoundPath + fileId + ".mp3";
    console.log("path = " + path);

    // Write the binary audio content to a local file

    fs.writeFile(path, response.audioContent, 'binary', err => {
      if (err) {
        console.error('ERROR:', err);
        return;
      }
    });
  });

  if (!text2 || text2 == "") {
    var result = [];
    result.push(fileId);
    return result;
  } else {
    var fileId2 = makepass();
    const request2 = {
      input: {
        text: text2
      },
      voice: {
        languageCode: voice,
        ssmlGender: 'FEMALE'
      },
      audioConfig: {
        audioEncoding: 'MP3'
      },
    };
    client.synthesizeSpeech(request2, (err, response) => {
      if (err) {
        console.error('ERROR:', err);
        return;
      }
      var path2 = tempSoundPath + fileId2 + ".mp3";

      // Write the binary audio content to a local file

      fs.writeFile(path2, response.audioContent, 'binary', err => {
        if (err) {
          console.error('ERROR:', err);
          return;
        }
      });
    });
    var result1 = [];
    result1.push(fileId, fileId2);
    return result1;
  }
}

重启不会强制页面重新加载(我只在流星控制台上看到它们),但我认为它们会减慢速度。

【问题讨论】:

标签: meteor


【解决方案1】:

我不知道您的 tempSoundPath 值是什么,但它的行为就像您正在将文件写入项目目录(在 server/... 中的某个位置)。

Meteor 将此视为源代码更改,并重新构建并重新启动服务器。

这甚至在生产环境中也行不通,因为您可能没有文件系统的写入权限。

最好将文件写入数据库,或者将它们传递到 S3 存储桶。有像 ostrio::files 这样的流星包可以帮助你解决这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多