Rails / delayed_job-要加载最新版本的职业 [英] Rails / delayed_job - want to load newest version of job class

查看:71
本文介绍了Rails / delayed_job-要加载最新版本的职业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Rails中使用delay_job插件进行后台处理,并且到目前为止,我在Rails中遇到的敏捷开发都遇到了麻烦...

I'm using the delayed_job plugin in Rails to do background processing, and I'm experiencing a hiccup in the 'agile development' I've been experiencing so far in Rails...

通常,如果遇到错误/想添加一些新功能-我只添加一些代码并刷新页面,新代码就会运行。

Usually in rails if I hit an error / want to add some new functionality - I just add some code and refresh the page and the new code runs.

使用delay_job,似乎没有重新加载作业类...如果作业失败,我去修复错误并再次启动作业,旧代码将再次运行。

With delayed_job, it seems like the job class isn't being reloaded... if a job fails and I go and fix the error and fire the job again, the old code runs again.

在调用它之前,有什么方法可以使delay_job加载作业类的最新版本吗?

Is there any way to make delayed_job load the newest version of the job class before invoking it?

如果这与它有任何关系-我知道delay_job在声明作业/运行作业的方式上有一些不同的选择:

Just in case this has anything to do with it - I know delayed_job has a few different options in the ways to declare jobs / run jobs:

我的作业类在lib中目录,并声明为:

My job class is in the lib directory of Rails and is declared like:

class FooJob < Struct.new(:foo_id)

我正在从控制器调用这样的工作:

and I'm invoking the job like this from the controller:

Delayed::Job.enqueue(FooJob.new(params[:id]))


推荐答案

没有内置函数可以执行此操作。通常,您负责管理和重新加载您的工人。由于Rails开发重装是好的,但不是完美的,这也可能是一样的,并且尝试自动重装延迟的作业可能会遇到各种各样的细微问题,这些问题在工作进程中很难调试。另外,如果它自动为每项工作重新加载环境,那么在开发人员模式下,许多用例将变得非常慢。

There is nothing builtin to do this. Generally you are responsible for managing and reloading your workers. This is probably just as well since Rails development reloading is good but not perfect, and attempting to auto-reload a delayed job would potentially run into all sort subtle issues that would be pretty opaque to debug inside a worker process. Also, if it automatically reloaded the environment for every job a lot of use cases would get tremendously slow in dev mode.

我的建议是习惯于 rake jobs:工作,然后进行更改,然后按 Ctrl-C 。或者,您可以创建一个脚本来临时手动运行作业(取自 delayed_job文档):

My suggestion is just to get use to doing rake jobs:work and then Ctrl-C when you make changes. Alternatively you can create a script that just manually runs the jobs on an ad-hoc basis (taken from delayed_job docs):

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'

Delayed::Worker.new.start  

这篇关于Rails / delayed_job-要加载最新版本的职业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆