Rails ActionCable - 监听或订阅后台进程

问题描述

我在我的控制器上有一个操作,它在 Sidekiq 中对作业进行排队。排队的作业有广播功能,希望在同一个请求上,我可以等待后台进程完成

Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 2212
Server version: 5.7.33-0ubuntu0.18.04.1 (Ubuntu)

copyright (c) 2000,2021,Oracle and/or its affiliates.

Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MysqL> SELECT 'new*\n*line' REGEXP 'new\\*.\\*line';
+---------------------------------------+
| 'new*\n*line' REGEXP 'new\\*.\\*line' |
+---------------------------------------+
|                                     1 |
+---------------------------------------+
1 row in set (0.00 sec)

MysqL>


===========

Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 1107
Server version: 8.0.23 MysqL Community Server - GPL

copyright (c) 2000,Oracle and/or its affiliates.

Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MysqL>
MysqL> SELECT 'new*\n*line' REGEXP 'new\\*.\\*line';
+---------------------------------------+
| 'new*\n*line' REGEXP 'new\\*.\\*line' |
+---------------------------------------+
|                                     0 |
+---------------------------------------+
1 row in set (0.00 sec)

MysqL>

这是后台作业

# controller
def process
  results = []
  uniq_id_across = record id
  20.times do |i|
    channel_id = "micro-#{uniq_id_across}-#{i}"
    MicroServices::DoThisJob.perform_async(channel_id,{some: params_here})
    
    # I would like to subscribe to the channel
  end

  # wait for the bg jobs to finish before return
  render json: results
end

我们的目标是在不使用可能导致 DB POOL 问题的 THREAD 的情况下进行几乎并行的处理。访问端点的用户对 PUB/SUB 一无所知,只知道正常的 API 调用、发送和接收。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...