2013-03-18 61 views
2

試圖在我的PHP作業基類中包裝Pheanstalk。我正在測試保留和延遲功能的儲備,我發現我可以從我的基類的第二個實例保留一份工作,而無需第一個實例釋放作業或TTR超時。這是意料之外的,因爲我認爲這正是工作隊列應該阻止的事情。這裏是第一次投入的beanstalkd命令和第一次保留以及時間戳。我還在最後做了一項統計工作要求:Beanstalkd(通過pheanstalk)允許重複,同時儲備?

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 

到目前爲止,這麼好。現在我從我的基類的第二個實例中做了另一個保留,然後是另一個stats-job請求。請注意,時間戳記在同一秒內,遠不及我設置的300秒TTR。另請注意,在此第二個統計作業打印輸出中,此作業有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 

任何人有什麼想法,我可能做錯了什麼?有什麼我需要做的事情來告訴隊列,我希望工作只能由一名工人一次訪問?一旦我將工作從隊列中取出,我相信會終止與beanstalkd的會話,我正在做一個「未設置」的pheanstalk實例。這是否會導致beanstalkd判定工作人員已經死亡,並在沒有超時的情況下自動釋放工作?我不確定有多少beanstalkd依賴會話狀態來確定工作人員狀態。我假設我可以不受懲罰地打開和關閉會議,並且該職位ID是beanstalkd關心的將工作操作綁在一起的唯一事情,但這可能對我來說是愚蠢的......這是我第一次進入工作隊列。

謝謝!

+0

我不知道問題是什麼,但我發現它在試圖確定爲什麼我的'pheanstalk->儲備()'調用被拖延 - 即不退還 - 導致我的cron作業無限期地運行,直到Apache有效地死亡。然而,我想說的是,一旦工作完成,你可能會想要刪除它。否則,它將保持在隊列中,然後每運行一次(最佳情況),只要有工作人員運行隊列作業,就會再次運行。就通信btwn pheanstalk實例被解除和釋放的工作,我不能評論。 – 2013-03-20 17:17:29

回答

2

我的猜測是你的第一個客戶端實例在第二個預留作業之前關閉了TCP套接字到beanstalkd服務器。

關閉TCP連接隱式地將作業釋放回隊列中。這些隱式版本(關閉連接,quit命令等)似乎不會增加releases計數器。

下面是一個例子:

# Create a job, reserve it, close the connection: 
[email protected] ~ > 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. 
[email protected] ~ > 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. 
[email protected] ~ > 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.