尝试在我的php作业基类中包装pheanstalk。我正在测试reserve和reserve with delay功能,我发现可以从基类的第二个实例中保留作业,而不需要第一个实例释放作业或ttr超时。这是出乎意料的,因为我认为这正是作业队列应该防止的事情。以下是第一次放置和第一次保留的beanstalk命令以及时间戳。最后我还做了一个统计工作请求:

01:40:15: Sending command: use QueuedCoreEvent
01:40:15: Got response: USING QueuedCoreEvent

01:40:15: Sending command: put 1024 0 300 233
a:4:{s:9:"eventName";s:21:"ReQueueJob_eawu7xr9bi";s:6:"params";a:2:{s:12:"InstanceName";s:21:"ReQueueJob_eawu7xr9bi";s:17:"aValueToIncrement";i:123456;}s:9:"behaviors";a:1:{i:0;s:22:"BehMCoreEventTestDummy";}s:12:"failureCount";i:0;}
01:40:15: Got response: INSERTED 10

01:40:15: Sending command: watch QueuedCoreEvent
01:40:15: Got response: WATCHING 2

01:40:15: Sending command: ignore default
01:40:15: Got response: WATCHING 1

01:40:15: Sending command: reserve-with-timeout 0
01:40:15: Got response: RESERVED 10 233
01:40:15: Data: a:4:{s:9:"eventName";s:21:"ReQueueJob_eawu7xr9bi";s:6:"params";a:2:{s:12:"InstanceName";s:21:"ReQueueJob_eawu7xr9bi";s:17:"aValueToIncrement";i:123456;}s:9:"behaviors";a:1:{i:0;s:22:"BehMCoreEventTestDummy";}s:12:"failureCount";i:0;}

01:40:15: Sending command: stats-job 10
01:40:15: Got response: OK 162
01:40:15: Data: ---
id: 10
tube: QueuedCoreEvent
state: reserved
pri: 1024
age: 0
delay: 0
ttr: 300
time-left: 299
file: 0
reserves: 1
timeouts: 0
releases: 0
buries: 0
kicks: 0

到目前为止,还不错。现在我从基类的第二个实例执行另一个reserve,然后执行另一个stats作业请求。注意,时间戳在同一秒之内,离我设置的300秒TTR还差得远。还要注意,在这个第二个stats作业打印输出中,这个作业有2个保留,0个超时和0个释放。
01:40:15: Sending command: watch QueuedCoreEvent
01:40:15: Got response: WATCHING 2

01:40:15: Sending command: ignore default
01:40:15: Got response: WATCHING 1

01:40:15: Sending command: reserve-with-timeout 0
01:40:15: Got response: RESERVED 10 233
01:40:15: Data: a:4:{s:9:"eventName";s:21:"ReQueueJob_eawu7xr9bi";s:6:"params";a:2:{s:12:"InstanceName";s:21:"ReQueueJob_eawu7xr9bi";s:17:"aValueToIncrement";i:123456;}s:9:"behaviors";a:1:{i:0;s:22:"BehMCoreEventTestDummy";}s:12:"failureCount";i:0;}

01:40:15: Sending command: stats-job 10
01:40:15: Got response: OK 162
01:40:15: Data: ---
id: 10
tube: QueuedCoreEvent
state: reserved
pri: 1024
age: 0
delay: 0
ttr: 300
time-left: 299
file: 0
reserves: 2
timeouts: 0
releases: 0
buries: 0
kicks: 0

有人知道我可能做错了什么吗?有什么事情需要我告诉队列我希望作业一次只能由一个工人访问吗?我正在对pheanstalk实例执行一个“unset”,只要我从队列中取出作业,我相信它会终止与beanstalkd的会话。这是否会导致beanstalkd确定工作进程已死亡并在不超时的情况下自动释放作业?我不确定beanstalk在多大程度上依赖会话状态来确定工作进程状态。我以为我可以不受惩罚地打开和关闭会话,而工作ID是Beanstalk唯一关心的将工作操作联系在一起的东西,但这对我来说可能是愚蠢的……这是我第一次进入工作队列。
谢谢!

最佳答案

我猜您的第一个客户机实例在第二个实例保留作业之前关闭了beanstalkd服务器的tcp套接字。
关闭TCP连接会隐式地将作业释放回队列中。这些隐式释放(关闭连接,quit命令等)似乎不会增加releases计数器。
下面是一个例子:

# Create a job, reserve it, close the connection:
pda@paulbookpro ~ > telnet 0 11300
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
put 0 0 600 5
hello
INSERTED 1
reserve
RESERVED 1 5
hello
^]
telnet> close
Connection closed.

# Reserve the job, stats-job shows two reserves, zero releases.
# Use 'quit' command to close connection.
pda@paulbookpro ~ > telnet 0 11300
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
reserve
RESERVED 1 5
hello
stats-job 1
OK 151
---
id: 1
tube: default
state: reserved
pri: 0
age: 33
delay: 0
ttr: 600
time-left: 593
file: 0
reserves: 2
timeouts: 0
releases: 0
buries: 0
kicks: 0

quit
Connection closed by foreign host.

# Reserve the job, stats-job still shows zero releases.
# Explicitly release the job, stats-job shows one release.
pda@paulbookpro ~ > telnet 0 11300
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
reserve
RESERVED 1 5
hello
stats-job 1
OK 151
---
id: 1
tube: default
state: reserved
pri: 0
age: 46
delay: 0
ttr: 600
time-left: 597
file: 0
reserves: 3
timeouts: 0
releases: 0
buries: 0
kicks: 0

release 1 0 0
RELEASED
stats-job 1
OK 146
---
id: 1
tube: default
state: ready
pri: 0
age: 68
delay: 0
ttr: 600
time-left: 0
file: 0
reserves: 3
timeouts: 0
releases: 1
buries: 0
kicks: 0

quit
Connection closed by foreign host.

10-08 12:39