In case anyone besides me is following this thread, it looks like a regular
unix timestamp does work just fine. I'm just unclear why it needs four
decimal places of accuracy.
Signing off!
E
DorkFest wrote:
>
> Okay, I've created a custom adapter class and a custom queue class, so I
> can set the timeout from the send() method of my custom queue class.
>
> I'm trying to understand the logic of the timeout variable. The database
> type is a decimal (14,4). I had hoped this would be a unix timestamp. I
> would be grateful if anyone knows the logic behind how this variable works
> or where a doc page is. Thanks!
>
> Also, does anyone know if I'm correct in assuming that by setting this
> timeout I can properly delay my queued jobs?
>
> Here are the custom classes in case they are helpful to anyone else (my
> namespace is GM).
>
> Queue class:
>
> <?php
>
> class GM_Queue extends Zend_Queue
> {
> public function send($message, $timeout = null)
> {
> return $this->getAdapter()->send($message, null, $timeout);
> }
> }
>
> Adapter class:
>
> <?php
>
> class GM_Queue_Adapter_Db extends Zend_Queue_Adapter_Db
> {
> public function send($message, Zend_Queue $queue = null, $timeout =
> null)
> {
> if ($queue === null) {
> $queue = $this->_queue;
> }
>
> if (is_scalar($message)) {
> $message = (string) $message;
> }
> if (is_string($message)) {
> $message = trim($message);
> }
>
> if (!$this->isExists($queue->getName())) {
> require_once 'Zend/Queue/Exception.php';
> throw new Zend_Queue_Exception('Queue does not exist:' .
> $queue->getName());
> }
>
> $msg = $this->_messageTable->createRow();
> $msg->queue_id = $this->getQueueId($queue->getName());
> $msg->created = time();
> $msg->body = $message;
> $msg->md5 = md5($message);
> $msg->timeout = $timeout;
>
> try {
> $msg->save();
> } catch (Exception $e) {
> require_once 'Zend/Queue/Exception.php';
> throw new Zend_Queue_Exception($e->getMessage(),
> $e->getCode());
> }
>
> $options = array(
> 'queue' => $queue,
> 'data' => $msg->toArray(),
> );
>
> $classname = $queue->getMessageClass();
> if (!class_exists($classname)) {
> require_once 'Zend/Loader.php';
> Zend_Loader::loadClass($classname);
> }
> return new $classname($options);
> }
> }
>
> And I was hoping usage could be something like:
>
> <?php
>
> $options = array(
> 'name' => Zend_Registry::get('config')->queue->message->event,
> 'driverOptions' =>
> Zend_Registry::get('config')->queue->driverOptions->toArray()
> );
> $queue = new GM_Queue(new GM_Queue_Adapter_Db($options), $options);
> $queue->send('Test', mktime() + 300); /* delay for 5 minutes */
>
>
>
>
> DorkFest wrote:
>>
>> I'm using Zend_Queue with the database adapter. And i have a job daemon
>> running that checks the the queue regularly and executes jobs.
>>
>> One need I have is to delay the execution of some jobs until precisely a
>> certain amount of time has passed. I see each message has a timeout field
>> in the table. But it doesn't seem as though Zend_Queue allows a way of
>> setting this at the time you send a message to the queue (in other words,
>> a timeout specific to that message).
>>
>> I'm thinking the approach is to extend the Zend_Queue class and simply
>> add this parameter to the send method. And then I would add that many
>> seconds to the timeout field for that job. And I suppose it could be tens
>> of thousands of seconds just fine (if it were weeks off, say). I wondered
>> if this functionality is achievable in a simpler way currently and if
>> anyone has any thoughts on this particular approach.
>>
>> Thanks!
>> Eddie
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/Zend_Queue-and-delayed-jobs-tp26053039p26054659.html
Sent from the Zend Framework mailing list archive at Nabble.com.