简体   繁体   English

在轨道上的 ruby 中,我怎样才能一一排队工作?

[英]in ruby on rails how can I queu the job one by one?

I have a big problem, I try to queu job one by one in a queu in ruby on rails.我有一个大问题,我尝试在轨道上 ruby 的队列中一个一个地排队工作。 I really need that the controller dont access at the same time to a liste of function because it is a long process and it use the databases during.我真的需要 controller 不要同时访问 function 的列表,因为这是一个漫长的过程,并且在此期间会使用数据库。 If two time the process is started at same time (or little differences) it will be conflict in my data.如果两次同时启动该过程(或差异很小),我的数据将发生冲突。

Thanks for your help,谢谢你的帮助,

Pierre皮埃尔

the most easy why is to put a static attribute in class最简单的原因是将 static 属性放入 class

class MyJob
   @@locked=0
   def perform(*args)
    while @@locked==1 do
        sleep(0.2)
    end
    @@locked=1
    # your code here
    @@locked=0
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为一个工作人员分配一个队列? - How do I assign one worker to a queu? 如何在 Ruby on Rails 中路由/引用一对一关系 - How can I route/reference one to one relationship in Ruby on Rails 我如何通过角色链接,Ruby on Rails来实现一个开关 - How i can do one switch with link by role, ruby on rails 如何跟踪一个用户在线的时间? 使用Ruby on Rails - How can track the time which one user is online? With Ruby on Rails 如何将一个查询结果映射到rails上的ruby中的另一个查询结果 - How can i map one query result to another query result in ruby on rails 在Ruby / Rails中,如何基于同一表中其他两列的值在表中创建一列? - In Ruby/Rails, how can I create one column in a table based on the value of two other columns in the same table? Ruby on Rails:如何从一个地方认证不同的用户类型? - Ruby on Rails: How can I authenticate different user types from one place? 如何为Windows上的Ruby on Rails应用程序部署创建多合一安装程序? - How can I create an all-in-one installer for Ruby on Rails application deployment on Windows? 如何在Rails中的ruby中在另一个对象的布局上添加一个对象? - How I can add an one object on the others object's layout in ruby on rails? 如何在Ruby-On-Rails质量分配中禁止一个或多个字段的分配? - How can I suppress the assignment of one or more fields in a Ruby-On-Rails mass-assignment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM