delayed job

delayed_job_active_record

https://github.com/collectiveidea/delayed_job_active_record

Installation

(1)Add the gem to your Gemfile:

gem ‘delayed_job_active_record‘

Run bundle install.

(2)If you‘re using Rails, run the generator to create the migration for the delayed_job table.

rails g delayed_job:active_record
bundle exec rake db:migrate

要是觉得不喜欢这个表名,可以在migrate修改表名。

(3)Running Jobs

script/delayed_job can be used to manage a background process which will start working off jobs.

To do so, add gem "daemons" to your Gemfile and make sure you‘ve run rails generate delayed_job.

You can then do the following:

RAILS_ENV=production script/delayed_job start
RAILS_ENV=production script/delayed_job stop

# Runs two workers in separate processes.
RAILS_ENV=production script/delayed_job -n 2 start
RAILS_ENV=production script/delayed_job stop

# Set the --queue or --queues option to work from a particular queue.
RAILS_ENV=production script/delayed_job --queue=tracking start
RAILS_ENV=production script/delayed_job --queues=mailers,tasks start

# Use the --pool option to specify a worker pool. You can use this option multiple times to start different numbers of workers for different queues.
# The following command will start 1 worker for the tracking queue,
# 2 workers for the mailers and tasks queues, and 2 workers for any jobs:
RAILS_ENV=production script/delayed_job --pool=tracking --pool=mailers,tasks:2 --pool=*:2 start

# Runs all available jobs and then exits
RAILS_ENV=production script/delayed_job start --exit-on-complete
# or to run in the foreground
RAILS_ENV=production script/delayed_job run --exit-on-complete
(4)insert and delete
 def set_push_at
 @video.update_attributes(:will_push_at => params[:cibn_video_broadcast_list][:will_push_at],
 :push_user => current_user_name)
 @video.delay(:run_at => @video.will_push_at).
 send( method_to_perform(@video), {:user_name => current_user_name})
 redirect_to :back, :notice => ‘操作成功‘
 end 

 def cancel_push_at
 @video.update_attributes(:will_push_at => nil)
 job = CibnPushDelayedJob.where(‘handler like ?‘ ,
 ["", "CibnVideoBroadcastList", "id: #{@video.id}", ""].join(‘%‘) ).last
 CibnPushDelayedJob.delete job.try(:id)
 redirect_to :back, :notice => ‘操作成功‘

时间: 2024-10-21 10:45:20

delayed job的相关文章

Delphi DLL制作和加载 Static, Dynamic, Delayed 以及 Shared-Memory Manager

一 Dll的制作一般分为以下几步:1 在一个DLL工程里写一个过程或函数2 写一个Exports关键字,在其下写过程的名称.不用写参数和调用后缀.二 参数传递1 参数类型最好与window C++的参数类型一致.不要用DELPHI的数据类型.2 最好有返回值[即使是一个过程],来报出调用成功或失败,或状态.成功或失败的返回值最好为1[成功]或0[失败].一句话,与windows c++兼容.3 用stdcall声明后缀.4 最好大小写敏感.5 无须用far调用后缀,那只是为了与windows 1

Linux下TCP延迟确认(Delayed Ack)机制导致的时延问题分析

版权声明:本文由潘安群原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/105 来源:腾云阁 https://www.qcloud.com/community 案例一:同事随手写个压力测试程序,其实现逻辑为:每秒钟先连续发N个132字节的包,然后连续收N个由后台服务回显回来的132字节包.其代码简化如下: char sndBuf[132]; char rcvBuf[132]; while (1) { for (int i

glance delayed delete image代码调用

glance支持延迟删除镜像的功能,个人觉得挺实用的,特别是在误删除的情况下.从某种程度来说,也算是对数据一种另类保护吧. 大致实现原理是:有个delayed_delete设置是否开启延迟删除的开关,如果为True的话,每次删除镜像的时候都会把镜像的状态置为pending_delete,记录此刻的delete_time,有个scrubber的后台进程会每隔一段时间(wakeup_time)去check是否有pending_delete的镜像要删除,删除的判断标准是:该镜像被删除的那个时刻的del

20150817---成长日记1---DelayQueue&&Delayed&&Other

今天第一次接触DelayQueue,源于项目中的话单解析入库的拆分线程中引入,首先简单了解一下DelayQueue: DelayQueue是一个无界阻塞队列,只有在延迟期满时才能从中提取元素.该队列的头部是延迟期满后保存时间最长的Delayed 元素. 问题1:如何来判断延迟期是否满了呢?   ----后面解答,下面继续. DelayQueue阻塞队列在我们系统开发中也常常会用到,例如:缓存系统的设计,缓存中的对象,超过了空闲时间,需要从缓存中移出:任务调度系统,能够准确的把握任务的执行时间.我

delayed ack与nagle's算法

delayed ack和nagles算法都能减少tcp传输过程中的小数据包的问题 tcpip卷二25章中提到tcp为每个连接建立7个定时器: 1.connection established 2.restransmission 3.delayed ack(https://en.wikipedia.org/wiki/TCP_delayed_acknowledgment) 4.persist 5.keepalive 6.fin_wait_2 7.time_wait 下面是wikipedia对nagl

What is Delayed ACK and how can it be a bottleneck

Before explaining what Delayed ACK is, lets start by clarifying some concepts.TCP/IP is used to refer to two different things. On one side TCP/IP is a suite of protocols that rule the Internet containing protocols like HTTP, Telnet,ICMP,SSH and many

SQL 2014新特性- Delayed durability

原文:SQL 2014新特性- Delayed durability ACID 是数据库的基本属性.其中的D是指"持久性":只要事务已经提交,对应的数据修改就会被保存下来,即使出现断电等情况,当系统重启后之前已经提交的数据依然能够反映到数据库中. 那么D特性是如何在SQL Server中实现的呢?SQL Server使用write-ahead logging的方式,保证日志记录会先于数据记录固化到磁盘中.当事务提交后,只有当日志记录固化到磁盘时,才会向客户端返回提交成功的消息,至于相应

INSERT DELAYED 句法

INSERT DELAYED ... INSERT 语句的 DELAYED 选项是一个 MySQL 特有的选项,如果你的客户端不能等待 INSERT 的完成,这将会是很有用的.This is a common problem when you use MySQL for logging and 当你打开日志记录使用 MySQL 并且你周期性的需花费很长时间才完成的 SELECT 和 UPDATE 语句时,这将是一个很普遍的问题.DELAYED 在 MySQL 3.22.15 中被引入.它是 My

exchange 2013 delayed FAN-OUT 的优点

最近在慢慢的学习 exchange 2013 的相关技术,在这个过程中看到的较重要的知识点希望能在这里做一个记录, 也能和大家一起来分享. 今天和大家分享的就就是  delayed fan-out 技术特点, 什么是delayed fan-out? 我的理解就是,就是为了解决当收件人多,且多数收件人在另一个站点,正常情况下发件服务器需要复制出和收件人数量相同的邮件副本,然后一一投递给相应收件人. 然而 delayed fan-out 就很好的解决了此问题, 例如 一封10MB大小的邮件的收件人收

1136 A Delayed Palindrome (20)

Consider a positive integer N written in standard notation with k+1 digits a~i~ as a~k~...a~1~a~0~ with 0 <= a~i~ < 10 for all i and a~k~ > 0. Then N is palindromic if and only if a~i~ = a~k-i~ for all i. Zero is written 0 and is also palindromic