小编lr_*_*tim的帖子

如何使用 Docker 设置 Django + RabbitMQ + Celery?

我正在尝试设置我的 Django 应用程序以具有推送通知功能。对于安排通知,我尝试使用 Celery,对于消息代理,我选择 RabbitMQ。我的应用程序在 Docker 容器中运行,我正在努力让 RabbitMQ 正常工作。Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.我在运行时收到错误消息docker-compose up。以下是我的celery以及rabbitmq3我的服务docker-compose.yml

celery:
    restart: always
    build:
      context: .
    command: celery -A test_celery worker -l info
    volumes:
      - .:/test_celery
    env_file:
      - ./.env
    depends_on:
      - app
      - rabbitmq3
  
rabbitmq3:
  container_name: "rabbitmq"
  image: rabbitmq:3-management-alpine
  ports:
    - 5672:5672
    - 15672:15672
Run Code Online (Sandbox Code Playgroud)

在我的test_celery-app 中,我有一个名为的文件celery.py,其中包含以下内容:

import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_celery.settings')

app = Celery('test_celery')
app.config_from_object('django.conf:settings', namespace='CELERY') …
Run Code Online (Sandbox Code Playgroud)

django rabbitmq celery docker docker-compose

4
推荐指数
1
解决办法
6444
查看次数

使用 ffmpeg 将 webm 转换为 wav

我已经成功地在 Python 中使用 ffmpeg 将 mp3 文件转换为 wav,以便我可以将它们发布到 Google Speech-To-Text。现在我对 webm 文件有同样的情况,我拥有的旧功能不起作用。它应该将文件转换为 wav 并将其拆分为 15 秒的块。我可以从 webm -file 执行此操作还是需要先将其转换为其他格式?

我用过的功能:

def convert_and_split(filename):
    command = ['ffmpeg', '-i', filename, '-f', 'segment', '-segment_time', '15', '-c', 'copy', 'parts/out%09d.wav']
    subprocess.run(command,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
Run Code Online (Sandbox Code Playgroud)

编辑。忘了提及该函数目前对 webm -files 的作用。它产生一个out000000000.wav空的wav 文件。在控制台中,我收到如下错误消息:

[segment @ 0x55970b22fe80] Opening 'parts/out000000000.wav' for writing
[wav @ 0x55970b1ffbc0] opus codec not supported in WAVE format
Could not write header for output file #0 (incorrect codec parameters ?): Function not implemented
Run Code Online (Sandbox Code Playgroud)

编辑2。我认为是对的,但想知道是否有更好的方法来做到这一点。

首先,我将文件转换为单声道 wav,然后将其拆分为多个块。请随时指出任何错误或错误。

def convert_webm_to_wav(file):
    command …
Run Code Online (Sandbox Code Playgroud)

python split ffmpeg wav webm

3
推荐指数
1
解决办法
5535
查看次数

如何使用 PostgreSQL 按路径过滤

我的数据库中有一些资源继承到它们的子资源。当我查询资源时,我还需要能够获取继承的资源。我有一个名为path我计划使用的字段。始终path包含与我们当前正在处理的资源相关的所有资源的完整路径。

例子:

+-----------------------------------------+
| id | res_id    | path                   |
|-----------------------------------------|
| 1  | res_1     | res_1                  |
| 2  | res_1.1   | res_1.res_1.1          |
| 3  | res_1.2   | res_1.res_1.2          |
| 4  | res_1.1.1 | res_1.res_1.1.res_1.1.1|
+-----------------------------------------+
Run Code Online (Sandbox Code Playgroud)

如果我查询res_1.1,我还必须获取 ,res_1因为它是 的父级res_1.1。如果我得到res_1.1.1,我还必须得到第 1 行和第 2 行,因为它们包含在 的路径中res_1.1.1。希望得到一些关于如何使用 Postgres 执行此操作的建议。如果这是重要信息,我也用来sqlmodel编写查询。

编辑。对于含糊的介绍,我深表歉意,该参数path已经是sqlalchemy Ltree字段。我希望这能让事情变得更简单一些?

python sql postgresql ltree sqlmodel

3
推荐指数
1
解决办法
466
查看次数

节点child_process等待结果

face_detection我有一个进行命令行调用的异步函数。否则一切正常,但我无法等待回复。这是我的功能:

async uploadedFile(@UploadedFile() file) {
    let isThereFace: boolean;
    const foo: child.ChildProcess = child.exec(
      `face_detection ${file.path}`,
      (error: child.ExecException, stdout: string, stderr: string) => {
        console.log(stdout.length);

        if (stdout.length > 0) {
          isThereFace = true;
        } else {
          isThereFace = false;
        }
        console.log(isThereFace);

        return isThereFace;
      },
    );

    console.log(file);

    const response = {
      filepath: file.path,
      filename: file.filename,
      isFaces: isThereFace,
    };
    console.log(response);

    return response;
  }
Run Code Online (Sandbox Code Playgroud)

isThereFace在我的响应中,我返回始终是undefined因为响应是在响应face_detection准备好之前发送给客户端的。我怎样才能做到这一点?

javascript child-process node.js async-await typescript

1
推荐指数
1
解决办法
8955
查看次数