我有一个混合Web应用程序,它在同一个Tomcat中运行Java WAR文件和JRuby WAR文件.
我们决定使用(JRuby)Resque作为我们的工作队列.对入队作业的调用如下所示:
Resque.enqueue(FooWorker, 111)
Run Code Online (Sandbox Code Playgroud)
其中FooWorker是JRuby端定义并使用的工作类(并包含在JRuby WAR文件中),当JRuby Resque rake任务处理队列中的作业时,它将被调用.
我想让Java代码能够将要由JRuby FooWorker类处理的Resque队列上的任务排队.
我在https://github.com/tc/call-jruby-from-java-example上查看了Tommy Cheng的代码.java文件
//JavaInterfaceExample.java
interface JavaInterfaceExample{
int add(int a, int b);
}
Run Code Online (Sandbox Code Playgroud)
和ruby文件
#JrubyAdderImpl.rb
require 'java'
class JrubyAdderImpl
include Java::JavaInterfaceExample
java_signature 'int add(int, int)'
def add(a, b)
a+b
end
end
Run Code Online (Sandbox Code Playgroud)
我怀疑我的代码看起来像:java文件
//ResqueInterfaceExample.java
interface ResqueInterfaceExample{
int resque_enqueue_foojob(int a);
}
Run Code Online (Sandbox Code Playgroud)
红宝石文件
#JrubyResqueImpl.rb
require 'java'
require 'resque'
class JrubyResqueImpl
include Java::ResqueInterfaceExample
java_signature 'int resque_enqueue_foojob(int)'
def resque_enqueue_foojob(a)
Resque.enqueue(FooWorker, a)
end
end
Run Code Online (Sandbox Code Playgroud)
我的FooWorker是一个类,它位于rails app的爆炸war文件目录中,文件是app/workers/foo_worker.rb
我需要做些什么来确保jruby编译器可以访问FooWorker和Resque JRuby类来正确编译代码?
我现在在两个应用程序上遇到了这个问题.Heroku本身还没有得到很多帮助(还).
我在用:
与我的本地Postgres和Redis数据库一起运行时,一切都很好.
这是我的Heroku日志中的错误示例:
2013-01-01T21:17:27+00:00 app[resque_worker.1]: Found job on #<Resque::Queue:0x00000006652920>
2013-01-01T21:17:27+00:00 app[resque_worker.1]: got: (Job{facebook} | FacebookRefresh | ["facebook_key"])
2013-01-01T21:17:27+00:00 app[resque_worker.1]: Running before_fork hooks with [(Job{facebook} | FacebookRefresh | ["facebook_key"])]
2013-01-01T21:17:27+00:00 app[resque_worker.1]: Running after_fork hooks with [(Job{facebook} | FacebookRefresh | ["facebook_key"])]
2013-01-01T21:17:27+00:00 app[resque_worker.1]: resque-2.0.0.pre.1: Processing facebook since 1357075047
2013-01-01T21:17:27+00:00 app[resque_worker.1]: resque-2.0.0.pre.1: Forked 503 at 1357075047
2013-01-01T21:17:27+00:00 app[resque_worker.1]: Running before_perform hooks with [(Job{facebook} | FacebookRefresh | ["facebook_key"])]
2013-01-01T21:17:27+00:00 app[resque_worker.1]: : SELECT a.attname, format_type(a.atttypid, …Run Code Online (Sandbox Code Playgroud) 如何在不同的服务器上运行 Resque 工作程序,但从一台 Redis 服务器轮询作业?
作为 resque 使用 redis 来监听所有作业,我正在寻找一种将参数传递给 worker 类的方法,以便 worker 可以连接到其他 redis 服务器。
我需要这个,因为一台服务器没有足够的资源来运行所有工人。
我们有一个Rails应用程序,其中某些请求在具有delayed_job的worker dyno上触发长时间运行的任务,而前端轮询直到它收到结果.
我们的流量虽小但增长很快,而且任务通常只需几秒钟即可完成,但最多可能需要一分钟.现在,每个web和worker dyno都足以处理我们的负载.
问题是,delayed_job队列不会并行处理作业,因此较长的任务最终会阻碍其后面的任务.
我们正在寻找的是类似于后端的Unicorn,其中单个工作人员可以同时处理多个任务.因为它是Rails,我们正在寻找多进程而不是多线程的东西.
(我们尝试在procfile中创建多个worker条目 - 这在本地开发框中工作,但在Heroku上没有)
Procfile:
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
# Multiple workers defined here doesn't translate into multiple processes on single worker dyno:
worker: bundle exec rake jobs:work
worker: bundle exec rake jobs:work
worker: bundle exec rake jobs:work
Run Code Online (Sandbox Code Playgroud)
这篇Heroku文章建议使用resque-pool gem作为解决方案.这是唯一的解决方案,还是delayed_job也可用于并行后台作业?
使用resque-scheduler根据用户的输入set_schedule动态cron作业时,似乎设置了计划,但工作人员实际上从未按设定的计划启动.
在Resque配置中,dynamic设置为true,如下所示:Resque :: Scheduler.dynamic = true我正在设置如下调度:
name = business.name + '_employee_import'
config = {}
config[:class] = 'ImporterWorker'
config[:args] = business.id.to_s
config[:cron] = cron_converter
config[:persist] = true
Resque.set_schedule(name, config)
Run Code Online (Sandbox Code Playgroud)
如果我在命令行中执行:
Resque.get_schedule("business_employee_import")
Run Code Online (Sandbox Code Playgroud)
我明白了:
{"class"=>"MyWorker", "args"=>"87", "cron"=>"19 18 * * * *"}
Run Code Online (Sandbox Code Playgroud)
但到了下午6点19分,工人才开始.我有一个工人正在运行,但工作永远不会被接收,我不知道为什么或如何排除故障.在我看来这应该工作.我也尝试将resque-scheduler更新到最新版本,但没有运气.
感谢您提供的任何帮助.
我正在尝试使用 rails 启动我的 rails 应用程序。这取决于 redis,它似乎可以正常工作,但是当 Rails 服务器启动时,它会失败并显示Cannot assign requested address - connect(2) for [::1]:6379 (Errno::EADDRNOTAVAIL).
FROM ruby:2.6.1
RUN apt-get update -yqq && \
apt-get install -yqq --no-install-recommends \
nodejs \
nano
COPY Gemfile* /usr/src/app/
WORKDIR /usr/src/app
RUN bundle install
RUN gem install foreman
RUN gem install rake -v 12.3.2
COPY . /usr/src/app/
CMD [ "bin/rails", "s", "-b", "0.0.0.0" ]
Run Code Online (Sandbox Code Playgroud)
version: '3'
services:
postgres:
image: 'postgres:10.3-alpine'
volumes:
- 'postgres:/var/lib/postgresql/data'
env_file:
- '.env'
redis:
image: 'redis'
# …Run Code Online (Sandbox Code Playgroud) rails 3.0.9的上下文,使用resque 1.17.1和resque-scheduler 2.0.0.0d.试图按照https://github.com/bvandenbos/resque-scheduler/tree/v2.0.0.d上的文档,我创建了一个resque_scheduler.rake文件:
# Resque tasks
require 'resque/tasks'
require 'resque_scheduler/tasks'
namespace :resque do
task :setup do
require 'resque'
require 'resque_scheduler'
require 'resque/scheduler'
# you probably already have this somewhere
Resque.redis = 'localhost:6379'
# The schedule doesn't need to be stored in a YAML, it just needs to
# be a hash. YAML is usually the easiest.
#Resque.schedule = YAML.load_file('your_resque_schedule.yml')
# If your schedule already has +queue+ set for each job, you don't
# need to require your …Run Code Online (Sandbox Code Playgroud)