- 浏览: 45085 次
- 性别:
- 来自: 大连
-
文章分类
最新评论
-
wangluo19:
刚刚好解决了我的问题,原来session factory可以把 ...
hibernate annotations和hbm.xml配置文件并存配置 -
vivei:
能者为师
ruby 1,9 多字节字符
这个bug是在使用delay_job(2.1.2)查出来的,后来google了一下,发现已经有人提交了这个问题
delay_job中如果有失败任务的话,后台会一直不停的运行失败任务
源代码修改,加注释的为原来的代码,注释后的为自己添加的修改代码
# Reserve a single job in a single update query. This causes workers to serialize on the # database and avoids contention. def self.reserve(worker, max_run_time = Worker.max_run_time) # affected_rows = 0 # ::ActiveRecord::Base.silence do # affected_rows = jobs_available_to_worker(worker.name, max_run_time).limit(1).update_all(["locked_at = ?, locked_by = ?", db_time_now, worker.name]) # end # if affected_rows == 1 # locked_by_worker(worker.name, max_run_time).first # else # nil # end #修改代码start success = false ::ActiveRecord::Base.silence do available_job = jobs_available_to_worker(worker.name, max_run_time).first success = available_job.update_attributes(:locked_at => db_time_now, :locked_by => worker.name) if available_job end if success locked_by_worker(worker.name, max_run_time).first else nil end #修改代码end end
引起的原因就是,那个update_all了。因为update_all前有limit处理,这样limit前的所有条件就会失效了,这样返回的结果就会始终有一个正在处理的任务。
[1]https://rails.lighthouseapp.com/projects/8994/tickets/6058-update_all-ignores-conditions-when-orders-and-limit-options-are-supplied
发表评论
-
rails 开源blog typo
2011-12-26 16:23 733rails open source blog: htt ... -
ROR网站
2011-07-07 10:56 962# gems http://rubygems.org/ ... -
Rail3 Plugs
2011-02-11 11:24 762Rails3 Plugs Gemfile [1] t ... -
Notifications in Rails 3
2011-02-11 10:34 1086249: Notifications in Rails 3 ... -
rails3 jquery ajax
2011-01-30 14:56 2587rails3中使用非form提交的ajax操作,这里使用的js ... -
插件扩展(2)
2011-01-28 16:41 841ruby:1.9.2 rails3.0.3 学习编写 ... -
插件扩展
2011-01-28 11:24 837在ruby on rails3 的guides,插件扩展中有这 ... -
关于restful_authentication密码更新问题
2011-01-05 22:28 1110使用restful_authentication插件时,进行更 ... -
rails3 flash 清除问题
2011-01-05 21:35 1240rails3请求之后,flash内容没有被清除? fl ... -
rails3 更新时间问题
2010-12-18 21:52 1296rails3 更新时间问题(updated_at) (未完) ... -
Ruby基本数据类型
2010-12-09 08:55 976d (转)http://blog.csdn.net/fore ... -
ruby 1,9 多字节字符
2010-12-08 08:53 989ruby 1.9 String类 length ... -
Here document
2010-12-07 08:55 821Here document 用于引入一段较复杂的内容, ... -
About Resouce
2010-12-02 21:40 860关于RESTful风格的URL设计 Singul ... -
Migration and Database Column Types
2010-11-30 23:09 983rails下迁移类与数据库类型对照表: M ... -
rails3 scope dead???
2010-11-29 18:37 1406看到一篇关于rails中是否还继续推荐使用scope的文章 ... -
Ruby Blocks
2010-11-22 08:41 895Ruby Blocks Block构成 ... -
each, map, collect
2010-11-22 08:38 766each, map, collect arr = ... -
使用cookie的session
2010-11-22 08:36 784使用cookie 的session 修改/depot/ ... -
Validation Helpers(数据验证)
2010-11-22 08:33 760validates_acceptance_of # c ...
相关推荐
tweets = Tweet.all.order(:zombie) ``` - **查询前 10 条记录**: ```ruby tweets = Tweet.all.limit(10) ``` #### 六、总结 Rails for Zombies 通过一系列生动有趣的示例,向学习者介绍了 Ruby on Rails 中...
named_scope :recent, lambda { {:order => 'created_at DESC', :limit => 5} } end Post.published.recent.all ``` ##### UTC为基础的迁移 为了更好地处理国际化问题,Rails 2.1的迁移命令现在默认使用UTC时间...
- 使用`where`方法时,可以使用哈希、字符串、范围等多种方式指定条件。 - `exists?`: 检查是否存在满足条件的记录。 四、动态Finder ActiveRecord还提供了一些预定义的动态查找方法,如`find_by`和`find_by!`,...
1. **SELECT语句**:用于从数据库中检索数据,可以使用WHERE子句进行条件过滤,GROUP BY进行分组,HAVING进行分组后的过滤,ORDER BY进行排序,LIMIT和OFFSET用于分页。 2. **INSERT INTO语句**:向表中插入新的记录...
users = User.order("created_at DESC").limit(10) ``` 更新记录: ```ruby user.update(name: "Jane Doe") ``` 删除记录: ```ruby user.destroy ``` ActiveRecord还支持关联,如一对一(has_one),一对多...
`Thinking-Sphinx` 支持多种高级搜索选项,如使用 `:with` 和 `:without` 过滤特定字段,`:order` 和 `:limit` 进行排序和分页,以及使用 `:conditions` 进行 SQL 风格的查询。 6. **实时索引** `Thinking-Sphinx...