请将例如公牛视为替代方案。谢谢你!
Kue是由Redis支持的优先职务队列,该k.
PROTIP这是最新的库文档,请确保还阅读Changelist。
最新版本:
$ npm install kue
主分支:
$ npm install http://github.com/Automattic/kue/tarball/master
首先使用kue.createQueue()
创建一个作业Queue
:
var kue = require ( 'kue' )
, queue = kue . createQueue ( ) ;
使用作业类型(“电子邮件”)调用queue.create()
,任意工作数据将返回Job
,然后可以save()
ed,将其添加到redis中,默认优先级为“正常”。 save()
方法可选地接受回调,如果出现error
,则会出现错误。 title
密钥是特殊的,将显示在UI中的作业清单中,从而更容易找到特定的作业。
var job = queue . create ( 'email' , {
title : 'welcome email for tj'
, to : '[email protected]'
, template : 'welcome-email'
} ) . save ( function ( err ) {
if ( ! err ) console . log ( job . id ) ;
} ) ;
要指定作业的优先级,只需调用带有数字或优先级名称的priority()
方法,将其映射到一个数字。
queue . create ( 'email' , {
title : 'welcome email for tj'
, to : '[email protected]'
, template : 'welcome-email'
} ) . priority ( 'high' ) . save ( ) ;
默认优先级映射如下:
{
low : 10
, normal : 0
, medium : - 5
, high : - 10
, critical : - 15
} ;
默认情况下,作业只有一次尝试,即当他们失败时,它们被标记为失败,并保持这种方式直到您进行干预。但是,Kue允许您指定此内容,这对于诸如传输电子邮件之类的工作很重要,该电子邮件通常在失败后可能会无问题重试。为此,用一个数字调用.attempts()
方法。
queue . create ( 'email' , {
title : 'welcome email for tj'
, to : '[email protected]'
, template : 'welcome-email'
} ) . priority ( 'high' ) . attempts ( 5 ) . save ( ) ;
即使您的工作通过Job#delay
设置了延迟,就可以尽快进行工作重试尝试。如果您想在失败时延迟作业重新攻击(称为退缩),则可以以不同的方式使用Job#backoff
方法:
// Honor job's original delay (if set) at each attempt, defaults to fixed backoff
job . attempts ( 3 ) . backoff ( true )
// Override delay value, fixed backoff
job . attempts ( 3 ) . backoff ( { delay : 60 * 1000 , type : 'fixed' } )
// Enable exponential backoff using original delay (if set)
job . attempts ( 3 ) . backoff ( { type : 'exponential' } )
// Use a function to get a customized next attempt delay value
job . attempts ( 3 ) . backoff ( function ( attempts , delay ) {
//attempts will correspond to the nth attempt failure so it will start with 0
//delay will be the amount of the last delay, not the initial delay unless attempts === 0
return my_customized_calculated_delay ;
} )
在最后一个方案中,将在每个重新攻击上执行(通过评估),以获取下一个尝试延迟值,这意味着您无法参考其中的外部/上下文变量。
求职者可以设定工作能够处于活跃状态的时间的到期价值,因此,如果工人没有及时回复,kue会在TTL exceeded
错误消息,从而阻止该作业处于活跃状态并破坏。并发。
queue . create ( 'email' , { title : 'email job with TTL' } ) . ttl ( milliseconds ) . save ( ) ;
特定于工作的日志使您可以在工作一生的任何时候将信息暴露于UI。为此,只需调用job.log()
,它接受消息字符串和可变题材的类似sprintf的支持:
job . log ( '$%d sent to %s' , amount , user . name ) ;
或其他任何东西(内部使用util.inspect()):
job . log ( { key : 'some key' , value : 10 } ) ;
job . log ( [ 1 , 2 , 3 , 5 , 8 ] ) ;
job . log ( 10.1 ) ;
工作进度对于长期运行的工作(例如视频转换)非常有用。要更新工作的进度,请简单地调用job.progress(completed, total [, data])
:
job . progress ( frames , totalFrames ) ;
数据可用于传递有关工作的额外信息。例如,消息或对象具有一些额外的上下文数据到当前状态。
通过Redis Pubsub在Job
实例上发射特定于工作的事件。目前支持以下事件:
enqueue
该工作现在排队start
工作现在正在运行promotion
该工作从延迟状态晋升为排队progress
工作的进度范围为0-100failed attempt
失败了,但仍在尝试failed
工作失败了,没有剩余的尝试complete
工作已经完成remove
工作已删除例如,这看起来像以下内容:
var job = queue . create ( 'video conversion' , {
title : 'converting loki's to avi'
, user : 1
, frames : 200
} ) ;
job . on ( 'complete' , function ( result ) {
console . log ( 'Job completed with data ' , result ) ;
} ) . on ( 'failed attempt' , function ( errorMessage , doneAttempts ) {
console . log ( 'Job failed' ) ;
} ) . on ( 'failed' , function ( errorMessage ) {
console . log ( 'Job failed' ) ;
} ) . on ( 'progress' , function ( progress , data ) {
console . log ( 'r job #' + job . id + ' ' + progress + '% complete with data ' , data ) ;
} ) ;
请注意,由于重新启动node.js流程将失去对特定工作对象的引用,因此不能保证在过程重新启动时收到工作级别事件。如果您想要一个更可靠的事件处理程序来寻找队列活动。
注意库将作业对象存储在内存中,直到它们完成/无法在其上散发事件为止。如果您在未完成的作业中具有巨大的并发性,请关闭此功能,并使用队列级别事件进行更好的内存缩放。
kue . createQueue ( { jobEvents : false } )
另外,您可以使用工作级功能events
来控制是否在工作级别上为作业发射事件。
var job = queue . create ( 'test' ) . events ( false ) . save ( ) ;
队列级事件提供了对前面提到的作业级事件的访问权限,但是范围范围为Queue
实例,以在“全局”级别应用逻辑。一个例子是删除完成的工作:
queue . on ( 'job enqueue' , function ( id , type ) {
console . log ( 'Job %s got queued of type %s' , id , type ) ;
} ) . on ( 'job complete' , function ( id , result ) {
kue . Job . get ( id , function ( err , job ) {
if ( err ) return ;
job . remove ( function ( err ) {
if ( err ) throw err ;
console . log ( 'removed completed job #%d' , job . id ) ;
} ) ;
} ) ;
} ) ;
可用的事件与“工作事件”中提到的事件相同,但是以“工作”为前缀。
可以通过调用.delay(ms)
方法,将延迟的作业安排为任意距离排队,并将其传递到现在的毫秒数。另外,您可以将来通过特定时间传递JavaScript Date
对象。这会自动将Job
标记为“延迟”。
var email = queue . create ( 'email' , {
title : 'Account renewal required'
, to : '[email protected]'
, template : 'renewal-email'
} ) . delay ( milliseconds )
. priority ( 'high' )
. save ( ) ;
Kue将使用计时器检查延迟的作业,如果超出计划的延迟,则将其促进它们,默认为每秒前1000名作业的检查。
使用Kue处理工作很简单。首先创建一个Queue
实例,就像我们为创建作业,为我们提供redis等的访问,然后使用关联类型调用queue.process()
。请注意,与createQueue
建议的名称不同,它当前返回Singleton Queue
实例。因此,您可以在Node.js进程中配置和使用一个Queue
对象。
在下面的示例中,我们将done
回调传递给email
,当发生错误时,我们调用done(err)
告诉kue发生某些事情,否则我们仅在作业完成时就调用done()
。如果此功能响应错误,则将显示在UI中,并且该作业将被标记为故障。传递给完成的错误对象应为标准类型Error
。
var kue = require ( 'kue' )
, queue = kue . createQueue ( ) ;
queue . process ( 'email' , function ( job , done ) {
email ( job . data . to , done ) ;
} ) ;
function email ( address , done ) {
if ( ! isValidEmail ( address ) ) {
//done('invalid to address') is possible but discouraged
return done ( new Error ( 'invalid to address' ) ) ;
}
// email send stuff...
done ( ) ;
}
工人还可以将工作结果作为完成的第二个参数done(null,result)
以将其存储在Job.result
键中。 result
还通过complete
活动处理程序传递,以便如果愿意的话,就可以收到它。
默认情况下,呼叫queue.process()
一次只能接受一项处理。对于诸如发送电子邮件之类的小任务,这不是理想的选择,因此我们可以通过一个数字来指定此类型的最大活动作业:
queue . process ( 'email' , 20 , function ( job , done ) {
// ...
} ) ;
工人可以暂时暂停并恢复他们的活动。也就是说,在调用pause
之后,他们将在调用resume
之前没有收到过程回调的工作。 pause
功能优雅地关闭了该工人,并在优雅关闭中使用与shutdown
方法相同的内部功能。
queue . process ( 'email' , function ( job , ctx , done ) {
ctx . pause ( 5000 , function ( err ) {
console . log ( "Worker is paused... " ) ;
setTimeout ( function ( ) { ctx . resume ( ) ; } , 10000 ) ;
} ) ;
} ) ;
请注意,来自kue的ctx
参数>=0.9.0
是过程回调函数的第二个参数,并且done
始终是最后一个
请注意, pause
方法签名已从kue >=0.9.0
更改为将回调函数移至最后一个。
对于一个“真实”示例,假设我们需要从带有节点 - 胶囊的众多幻灯片中编译PDF。我们的工作可能包含以下数据,请注意,通常您不应将大量数据存储在工作中,最好存储像ID之类的参考,在处理时将其拉入。
queue . create ( 'slideshow pdf' , {
title : user . name + "'s slideshow"
, slides : [ ... ] // keys to data stored in redis, mongodb, or some other store
} ) ;
我们可以通过job.data
属性在处理时在单独的过程中访问相同的任意数据。在示例中,我们渲染每个幻灯片一对一,更新作业的日志和进度。
queue . process ( 'slideshow pdf' , 5 , function ( job , done ) {
var slides = job . data . slides
, len = slides . length ;
function next ( i ) {
var slide = slides [ i ] ; // pretend we did a query on this slide id ;)
job . log ( 'rendering %dx%d slide' , slide . width , slide . height ) ;
renderSlide ( slide , function ( err ) {
if ( err ) return done ( err ) ;
job . progress ( i , len , { nextSlide : i == len ? 'itsdone' : i + 1 } ) ;
if ( i == len ) done ( )
else next ( i + 1 ) ;
} ) ;
}
next ( 0 ) ;
} ) ;
Queue#shutdown([timeout,] fn)
在完成当前的活动作业后,所有工人都会停止处理。工人将等待timeout
毫秒,以便将其主动作业称为“被调用”或“关闭错误原因”的主动作业failed
。当所有工人告诉Kue时,他们被停止了fn
。
var queue = require ( 'kue' ) . createQueue ( ) ;
process . once ( 'SIGTERM' , function ( sig ) {
queue . shutdown ( 5000 , function ( err ) {
console . log ( 'Kue shutdown: ' , err || '' ) ;
process . exit ( 0 ) ;
} ) ;
} ) ;
请注意, shutdown
方法签名从库>=0.9.0
更改为将回调函数移至最后一个。
REDIS客户库中的所有错误或队列都散发到Queue
对象。您应该绑定到error
事件,以防止未知的异常或调试库错误。
var queue = require ( 'kue' ) . createQueue ( ) ;
queue . on ( 'error' , function ( err ) {
console . log ( 'Oops... ' , err ) ;
} ) ;
Kue标记了您的工人调用done
后完成/失败的工作,因此您应该使用适当的错误处理来防止工人代码中未知的例外和Node.js进程在手柄作业之前退出。这可以通过两种方式实现:
queue . process ( 'my-error-prone-task' , function ( job , done ) {
var domain = require ( 'domain' ) . create ( ) ;
domain . on ( 'error' , function ( err ) {
done ( err ) ;
} ) ;
domain . run ( function ( ) { // your process function
throw new Error ( 'bad things happen' ) ;
done ( ) ;
} ) ;
} ) ;
通知 -域是从稳定性0的nodej中弃用,不建议使用。
这是最柔软,最佳的解决方案,但是不是与库一起内置的。请参阅此讨论。您可以在相关的开放式问题中对此功能发表评论。
您也可以使用承诺做类似的事情
queue . process ( 'my-error-prone-task' , function ( job , done ) {
Promise . method ( function ( ) { // your process function
throw new Error ( 'bad things happen' ) ;
} ) ( ) . nodeify ( done )
} ) ;
但这不会像域那样在异步调用堆栈中捕获异常。
uncaughtException
并优雅地关闭了库,但是这不是建议在JavaScript中处理成语的建议,因为您正在失去错误上下文。 process . once ( 'uncaughtException' , function ( err ) {
console . error ( 'Something bad happened: ' , err ) ;
queue . shutdown ( 1000 , function ( err2 ) {
console . error ( 'Kue shutdown result: ' , err2 || 'OK' ) ;
process . exit ( 0 ) ;
} ) ;
} ) ;
Kue当前使用客户端的工作状态管理以及REDIS在该操作中间崩溃时,会发生一些卡住的工作或索引不一致。结果是,只有创建新的作业,如果没有再创造新的工作,他们将永远卡住,他们才会被工人撤出,并被工人撤出。因此,我们强烈建议您通过致电:
queue . watchStuckJobs ( interval )
interval
为毫秒,默认为1000ms
Kue将重构为1.0版的完全原子工作状态管理,这将通过LUA脚本和/或BRPOPLPUSH组合进行。您可以在这里和这里阅读更多。
队列对象有两种类型的方法来告诉您每个状态的作业数量
queue . inactiveCount ( function ( err , total ) { // others are activeCount, completeCount, failedCount, delayedCount
if ( total > 100000 ) {
console . log ( 'We need some back pressure here' ) ;
}
} ) ;
您也可以查询特定的作业类型:
queue . failedCount ( 'my-critical-job' , function ( err , total ) {
if ( total > 10000 ) {
console . log ( 'This is tOoOo bad' ) ;
}
} ) ;
并迭代工作ID
queue . inactive ( function ( err , ids ) { // others are active, complete, failed, delayed
// you may want to fetch each id to get the Job object out of it...
} ) ;
但是,第二个没有扩展到大型部署,您可以使用更具体的Job
静态方法:
kue . Job . rangeByState ( 'failed' , 0 , n , 'asc' , function ( err , jobs ) {
// you have an array of maximum n Job objects here
} ) ;
或者
kue . Job . rangeByType ( 'my-job-type' , 'failed' , 0 , n , 'asc' , function ( err , jobs ) {
// you have an array of maximum n Job objects here
} ) ;
请注意,最后两种方法可能会更改以后的库版本。
如果您在错误处理部分或以任何方式丢失了主动作业的过程中没有做任何事情,则可以在重新启动过程时从它们中恢复过来。盲目的逻辑是重新加入所有卡住的工作:
queue . active ( function ( err , ids ) {
ids . forEach ( function ( id ) {
kue . Job . get ( id , function ( err , job ) {
// Your application should check if job is a stuck one
job . inactive ( ) ;
} ) ;
} ) ;
} ) ;
注意在集群部署中,您的应用程序应该注意不要涉及有效的作业,目前是其他工人的工作。
作业数据和搜索索引占据了重新的内存空间,因此您需要在现实世界部署中进行一些工作。您的第一个机会是在完成时使用自动删除工作。
queue . create ( ... ) . removeOnComplete ( true ) . save ( )
但是,如果您最终/暂时需要完成的工作数据,则可以设置一个按需删除脚本, n
kue . Job . rangeByState ( 'complete' , 0 , n , 'asc' , function ( err , jobs ) {
jobs . forEach ( function ( job ) {
job . remove ( function ( ) {
console . log ( 'removed ' , job . id ) ;
} ) ;
} ) ;
} ) ;
请注意,您应该为每个工作对象.remove
足够的时间来完成。
默认情况下,Kue将使用客户端默认设置连接到REDIS(端口默认为6379
,主机默认为127.0.0.1
,前缀默认为q
)。 Queue#createQueue(options)
接受options.redis
键中的redis连接选项。
var kue = require ( 'kue' ) ;
var q = kue . createQueue ( {
prefix : 'q' ,
redis : {
port : 1234 ,
host : '10.0.50.20' ,
auth : 'password' ,
db : 3 , // if provided select a non-default redis db
options : {
// see https://github.com/mranney/node_redis#rediscreateclient
}
}
} ) ;
prefix
控制Redis中使用的关键名称。默认情况下,这只是q
通常不应更改前缀,除非您需要为多个应用程序使用一个redis实例。它对于在主应用程序中提供隔离的测试台也很有用。
您还可以将连接信息指定为URL字符串。
var q = kue . createQueue ( {
redis : 'redis://example.com:1234?redis_option=value&redis_option=value'
} ) ;
由于Node_redis支持Unix域插座,因此您也可以告诉Kue这样做。有关REDIS服务器配置,请参见Unix-Domain插座。
var kue = require ( 'kue' ) ;
var q = kue . createQueue ( {
prefix : 'q' ,
redis : {
socket : '/data/sockets/redis.sock' ,
auth : 'password' ,
options : {
// see https://github.com/mranney/node_redis#rediscreateclient
}
}
} ) ;
任何符合node_redis api符合符合(或适应)的node.js redis客户库都可以注入kue。您应该仅提供createClientFactory
函数作为REDIS连接工厂,而不是提供Node_redis连接选项。
以下是一个示例代码,可以使Redis-Sentinel连接到Redis Sentinel以进行自动主/从失败转移。
var kue = require ( 'kue' ) ;
var Sentinel = require ( 'redis-sentinel' ) ;
var endpoints = [
{ host : '192.168.1.10' , port : 6379 } ,
{ host : '192.168.1.11' , port : 6379 }
] ;
var opts = options || { } ; // Standard node_redis client options
var masterName = 'mymaster' ;
var sentinel = Sentinel . Sentinel ( endpoints ) ;
var q = kue . createQueue ( {
redis : {
createClientFactory : function ( ) {
return sentinel . createClient ( masterName , opts ) ;
}
}
} ) ;
请注意,所有<0.8.x
客户端代码都应重构以将redis选项传递为Queue#createQueue
而不是猴子修补的样式redis#createClient
的覆盖层,否则它们将从kue 0.8.x
中损坏。
var Redis = require ( 'ioredis' ) ;
var kue = require ( 'kue' ) ;
// using https://github.com/72squared/vagrant-redis-cluster
var queue = kue . createQueue ( {
redis : {
createClientFactory : function ( ) {
return new Redis . Cluster ( [ {
port : 7000
} , {
port : 7001
} ] ) ;
}
}
} ) ;
UI是一个小快报。在bin/
中提供了一个脚本,用于将接口作为具有默认设置的独立应用程序运行。您可以传递端口,redis-url和前缀的选项。例如:
node_modules/kue/bin/kue-dashboard -p 3050 -r redis://127.0.0.1:3000 -q prefix
您也可以在另一个应用程序中启动它:
var kue = require ( 'kue' ) ;
kue . createQueue ( ... ) ;
kue . app . listen ( 3000 ) ;
标题默认为“库”,以更改此调用:
kue . app . set ( 'title' , 'My Application' ) ;
请注意,如果您使用的是非默认kue选项,则必须在访问kue.app
之前调用kue.createQueue(...)
。
您也可以使用ArnaudBénard贡献的Kue-UI Web界面
与UI库一起,还暴露了一个由UI使用的JSON API。
查询作业,例如“ get /job /search?q = avi视频”:
[ "5" , "7" , "10" ]
默认情况下,kue索引了整个作业数据对象进行搜索,但是可以通过调用Job#searchKeys
来自定义kue,以告诉kue在工作数据上要创建索引上的哪些键:
var kue = require ( 'kue' ) ;
queue = kue . createQueue ( ) ;
queue . create ( 'email' , {
title : 'welcome email for tj'
, to : '[email protected]'
, template : 'welcome-email'
} ) . searchKeys ( [ 'to' , 'title' ] ) . save ( ) ;
默认情况下关闭搜索功能>=0.9.0
。在此处阅读有关此信息的更多信息。如果需要:
var kue = require ( 'kue' ) ;
q = kue . createQueue ( {
disableSearch : false
} ) ;
npm install reds --save
目前以国家计数和工人活动时间的响应毫秒:
{ "inactiveCount" : 4 , "completeCount" : 69 , "activeCount" : 2 , "failedCount" : 0 , "workTime" : 20892 }
通过:id
:
{ "id" : "3" , "type" : "email" , "data" : { "title" : "welcome email for tj" , "to" : "[email protected]" , "template" : "welcome-email" } , "priority" : - 10 , "progress" : "100" , "state" : "complete" , "attempts" : null , "created_at" : "1309973155248" , "updated_at" : "1309973155248" , "duration" : "15002" }
获取工作:id
的日志:
[ 'foo' , 'bar' , 'baz' ]
获取具有指定范围的工作:from
:to
:例如“/jobs/0..2”,其中:order
可能为“ asc”或“ desc”:
[ { "id" : "12" , "type" : "email" , "data" : { "title" : "welcome email for tj" , "to" : "[email protected]" , "template" : "welcome-email" } , "priority" : - 10 , "progress" : 0 , "state" : "active" , "attempts" : null , "created_at" : "1309973299293" , "updated_at" : "1309973299293" } , { "id" : "130" , "type" : "email" , "data" : { "title" : "welcome email for tj" , "to" : "[email protected]" , "template" : "welcome-email" } , "priority" : - 10 , "progress" : 0 , "state" : "active" , "attempts" : null , "created_at" : "1309975157291" , "updated_at" : "1309975157291" } ]
与上述相同,限制以下限制:state
是:
- active
- inactive
- failed
- complete
与上述相同,多么限于:type
和:state
。
删除工作:id
:
$ curl -X DELETE http://local:3000/job/2
{"message":"job 2 removed"}
创建工作:
$ curl -H "Content-Type: application/json" -X POST -d
'{
"type": "email",
"data": {
"title": "welcome email for tj",
"to": "[email protected]",
"template": "welcome-email"
},
"options" : {
"attempts": 5,
"priority": "high"
}
}' http://localhost:3000/job
{"message": "job created", "id": 3}
您可以通过阵列一次创建多个作业。在这种情况下,响应也将是一个数组,保留了订单:
$ curl -H "Content-Type: application/json" -X POST -d
'[{
"type": "email",
"data": {
"title": "welcome email for tj",
"to": "[email protected]",
"template": "welcome-email"
},
"options" : {
"attempts": 5,
"priority": "high"
}
},
{
"type": "email",
"data": {
"title": "followup email for tj",
"to": "[email protected]",
"template": "followup-email"
},
"options" : {
"delay": 86400,
"attempts": 5,
"priority": "high"
}
}]' http://localhost:3000/job
[
{"message": "job created", "id": 4},
{"message": "job created", "id": 5}
]
注意:批量插入多个作业时,如果一个插入失败,则kue将继续按顺序处理剩余的作业。响应阵列将包含成功添加的作业的ID,任何失败的元素将是描述错误的对象: {"error": "error reason"}
。
下面的示例显示了如何使用群集在CPU上扩散工作加载负载。请参阅群集模块的文档,以获取有关使用它的更多详细示例。
当cluster .isMaster
在主过程的上下文中执行文件时,在这种情况下,您可以执行仅需要一次的任务,例如启动Web应用程序与Kue捆绑在一起。每个工人都执行else
块中的逻辑。
var kue = require ( 'kue' )
, cluster = require ( 'cluster' )
, queue = kue . createQueue ( ) ;
var clusterWorkerSize = require ( 'os' ) . cpus ( ) . length ;
if ( cluster . isMaster ) {
kue . app . listen ( 3000 ) ;
for ( var i = 0 ; i < clusterWorkerSize ; i ++ ) {
cluster . fork ( ) ;
}
} else {
queue . process ( 'email' , 10 , function ( job , done ) {
var pending = 5
, total = pending ;
var interval = setInterval ( function ( ) {
job . log ( 'sending!' ) ;
job . progress ( total - pending , total ) ;
-- pending || done ( ) ;
pending || clearInterval ( interval ) ;
} , 1000 ) ;
} ) ;
}
这将根据每台机器CPU内核创建一个email
工作处理器(Worker),每个机器都可以处理10个并发的电子邮件作业,从而导致10 * N
并发的电子邮件作业在您的N
Core Machine中处理。
现在,当您在浏览器中访问Kue的UI时,您会发现N
更快地处理工作! (如果您有N
内核)。
通过使用应用程序安装,您可以自定义Web应用程序,启用TLS或添加其他中间件(例如basic-auth-connect
。
$ npm install --save basic-auth-connect
var basicAuth = require ( 'basic-auth-connect' ) ;
var app = express . createServer ( { ... tls options ... } ) ;
app . use ( basicAuth ( 'foo' , 'bar' ) ) ;
app . use ( kue . app ) ;
app . listen ( 3000 ) ;
启用测试模式可以将所有作业推向jobs
数组。对该数组中的工作做出断言,以确保正在测试的代码正确地完成工作。
queue = require ( 'kue' ) . createQueue ( ) ;
before ( function ( ) {
queue . testMode . enter ( ) ;
} ) ;
afterEach ( function ( ) {
queue . testMode . clear ( ) ;
} ) ;
after ( function ( ) {
queue . testMode . exit ( )
} ) ;
it ( 'does something cool' , function ( ) {
queue . createJob ( 'myJob' , { foo : 'bar' } ) . save ( ) ;
queue . createJob ( 'anotherJob' , { baz : 'bip' } ) . save ( ) ;
expect ( queue . testMode . jobs . length ) . to . equal ( 2 ) ;
expect ( queue . testMode . jobs [ 0 ] . type ) . to . equal ( 'myJob' ) ;
expect ( queue . testMode . jobs [ 0 ] . data ) . to . eql ( { foo : 'bar' } ) ;
} ) ;
重要:默认情况下,在测试模式下创建时未处理作业。您可以通过将TREA TREA转到TestMode.enter来启用工作处理
before ( function ( ) {
queue . testMode . enter ( true ) ;
} ) ;
我们喜欢贡献!
贡献时,请遵循简单的规则:
(麻省理工学院许可证)
版权(c)2011 LearnBoost <[email protected]>
特此免费授予任何获得此软件副本和相关文档文件(“软件”)的人,以无限制处理该软件,包括无限制的使用权,复制,修改,修改,合并,发布,分发,分布和/或出售该软件的副本,并允许提供该软件的人,但要遵守以下条件:
上述版权通知和此许可通知应包含在软件的所有副本或大量部分中。
该软件是“按原样”提供的,没有任何形式的明示或暗示保证,包括但不限于适销性,适合特定目的和非侵害的保证。在任何情况下,作者或版权持有人均不应对任何索赔,损害赔偿或其他责任责任,无论是在合同,侵权或其他方面的诉讼中,与软件或与软件或使用或其他交易有关的诉讼或其他责任软件。