我在Rails中找到了这个 Schedule一次性工作, 但这只显示了如何一次性安排.我有兴趣安排一份经常性的工作.
Delayed_job有这个
self.delay(:run_at => 1.minute.from_now)
Run Code Online (Sandbox Code Playgroud)
我如何在Rails 4.2/Active Job中做类似的事情?
我创建了一个应用程序并将其部署到Heroku,但我没有github git repo(我知道真的很糟糕!)并且我的本地git repo已被删除(这里只是简单的愚蠢).所以我没有我的来源副本.我需要做一些更新,我唯一能想到的是从Heroku进行结账.
有没有办法从Heroku结帐?有没有办法从Heroku git repo中检索源代码?
有没有人能够在Rails 4.2中获得预定的工作?
我正在使用resque,我正在尝试使用resque-scheduler来安排作业.我有一个计划加载和调度程序运行,甚至看起来它正在运行作业但它没有做任何事情.
resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Starting
resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Loading Schedule
resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Scheduling friends
resque-scheduler: [INFO] 2014-09-16T01:54:25-07:00: Schedules Loaded
resque-scheduler: [INFO] 2014-09-16T01:54:55-07:00: queueing FriendsJob (friends)
Run Code Online (Sandbox Code Playgroud)
我可以将这样的工作排队,然后进行处理.
TestJob.enqueue(params[:id])
Run Code Online (Sandbox Code Playgroud)
我在工作日志中得到了这个输出
got: (Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | ["TestJob", "98732ce5-17f7-4da3-9a03-a5d2f8f74e84", "8"])
** [01:24:01 2014-09-16] 54841: resque-1.25.2: Processing default since 1410855841 [ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper]
** [01:24:01 2014-09-16] 54841: Running before_fork hooks with [(Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | ["TestJob", "98732ce5-17f7-4da3-9a03-a5d2f8f74e84", "8"])]
** [01:24:01 2014-09-16] 54841: resque-1.25.2: Forked 54882 at 1410855841
** [01:24:01 2014-09-16] 54882: Running after_fork hooks …Run Code Online (Sandbox Code Playgroud) ruby-on-rails resque ruby-on-rails-4 resque-scheduler rails-activejob
我正在用RSpec编写一个视图规范,我不断遇到这个问题.测试会找到textarea但是当我尝试测试内容时它会失败.有什么建议?
这是我遇到麻烦的测试.
describe "reminders/edit.html.erb" do
before(:each) do
@reminder = Factory(:reminder)
end
it "should render the form to edit a reminder" do
assign :reminder, @reminder
render
rendered.should have_selector("form", :method => "post", :action => reminder_path(@reminder) ) do |f|
f.should have_selector("input", :type => "text", :name => "reminder[title]", :value => "The Title" )
f.should have_selector("textarea", :name => "reminder[content]", :value => 'The big content')
f.should have_selector("input", :type => "submit")
end
end
Run Code Online (Sandbox Code Playgroud)
我可能做错了,因为我在TDD上很新,但是当我从textarea中删除了真正让我困惑的值时,我看到这个测试通过了.那么有没有办法测试textarea的内容?
我在Rails 4.2和Resque中使用ActiveJob有点困难.
我已经安装了redis,并且已经将resque和resque-scheduler添加到我的Gemfile中.
我创建了一个测试作业 - 它只是生成的文件
rails g job test
Run Code Online (Sandbox Code Playgroud)
但我一直没有定义ActiveJob的错误
NameError: uninitialized constant ActiveJob
Run Code Online (Sandbox Code Playgroud)
当我像这样切换适配器时,或丢失方法
config.active_job.queue_adapter = :resque
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0.beta1/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `active_job' for #<Rails::Application::Configuration:0x007f97ba98a5b8> (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
我甚至看过源代码,但我不知道.它只是叫超级.
https://github.com/rails/rails/blob/master/railties/lib/rails/railtie/configuration.rb#L95
我错过了什么?为什么队列适配器不起作用?有谁知道如何解决这一问题?
我试图在我的控制器上测试更新操作的失败分支,但我在测试时遇到问题.这就是我所拥有的,它最后失败了
describe "PUT 'article/:id'" do
.
.
.
describe "with invalid params" do
it "should find the article and return the object" do
Article.stub(:find).with("1").and_return(@article)
end
it "should update the article with new attributes" do
Article.stub(:update_attributes).and_return(false)
end
it "should render the edit form" do
response.should render_template("edit")
end
end
end
Run Code Online (Sandbox Code Playgroud)
关于为什么最后一部分无法呈现模板的任何想法?
我有一个case语句,我试图使用三元运算符进行额外的条件检查.但它出错了.
这是代码示例
case url
when partner_x_url then Rails.env.development? ? partner_signup_url : partner_signup_url :protocol => "https"
.
.
.
else regular_signup_url
end
Run Code Online (Sandbox Code Playgroud)
真正奇怪的是,如果使用以下内容,它可以工作
case url
when partner_x_url then if Rails.env.development?; partner_signup_url; else partner_signup_url :protocol => "https"; end
.
.
.
else regular_signup
end
Run Code Online (Sandbox Code Playgroud)
有关为什么会发生这种情况的任何想法?