opportunisticqueuemanager.php

Summary
opportunisticqueuemanager.php
Opportunistic Queue ManagerGNU social queue-manager-on-visit class
OpportunisticQueueManagerDatabase-based queue that runs on pageload
__constructClass constructor
verifyKeyVerify that the key matches what was set in the configuration
canContinueDetermine whether we can continue processing items in the queue.
pollRun a polling cycle during idle processing in the input loop.
noHandlerFoundOpportunisticQM shouldn’t discard items it can’t handle, we’re only here to take care of what we can handle!
_failFree our claimed queue item for later reprocessing in case of temporary failure.
runQueueTakes care of running through the queue items, returning when the limits setup in __construct are met.

Opportunistic Queue Manager

GNU social queue-manager-on-visit class

postActiv

the micro-blogging software

Copyright

Copyright © 2016-2017, Maiyannah Bishop

Derived from code copyright various sources

  • GNU Social © 2013-2016, Free Software Foundation, Inc
  • StatusNet © 2008-2012, StatusNet, Inc

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses/.

https://www.gnu.org/licenses/agpl.html

About

GNU social queue-manager-on-visit class

Will run events for a certain time, or until finished.

Configure remote key if wanted with $config[‘opportunisticqm’][‘qmkey’] and use with /main/runqueue?qmkey=abc123

PHP version

Tested with PHP 7

File Authors

Web

OpportunisticQueueManager

Database-based queue that runs on pageload

Defines

  • MAXEXECTIME - typically just used for the /main/cron action, only used if php.ini max_execution_time is 0

Variables

  • $qmkey - Queue key
  • $max_execution_time - maximum time in seconds for execution
  • $max_dececution_margin - margin to PHP’s max_execution_time
  • $max_queue_items - maximum number of queue items
  • $started_at - time execution started
  • $handled_items - number of items handled
  • $verbosity - log verbosity level
Summary
__constructClass constructor
verifyKeyVerify that the key matches what was set in the configuration
canContinueDetermine whether we can continue processing items in the queue.
pollRun a polling cycle during idle processing in the input loop.
noHandlerFoundOpportunisticQM shouldn’t discard items it can’t handle, we’re only here to take care of what we can handle!
_failFree our claimed queue item for later reprocessing in case of temporary failure.
runQueueTakes care of running through the queue items, returning when the limits setup in __construct are met.

__construct

public function __construct(array $args = array())

Class constructor

Parameters

  • array $args - Arguments array

Returns

  • boolean on success

verifyKey

protected function verifyKey()

Verify that the key matches what was set in the configuration

Returns

  • boolean true if key matches

Error state

Will throw a RunQueueBadKeyException if the key doesn’t match

canContinue

public function canContinue()

Determine whether we can continue processing items in the queue.

Returns

  • boolean true if we can continue, false if we should wait instead

poll

public function poll()

Run a polling cycle during idle processing in the input loop.

Returns

  • boolean true if we should poll again for more data immediately

noHandlerFound

protected function noHandlerFound(Queue_item $qi,  
 $rep = null)

OpportunisticQM shouldn’t discard items it can’t handle, we’re only here to take care of what we can handle!

Parameters

  • Queue_item $qi - a queue item
  • mixed $rep

_fail

protected function _fail(Queue_item $qi,  
 $releaseOnly = false)

Free our claimed queue item for later reprocessing in case of temporary failure.

Parameters

  • QueueItem $qi - a queue item
  • boolean $releaseOnly - whether to not report an error on failure

runQueue

public function runQueue()

Takes care of running through the queue items, returning when the limits setup in __construct are met.

Returns

  • true on workqueue finished, false if there are still items in the queue
public function __construct(array $args = array())
Class constructor
protected function verifyKey()
Verify that the key matches what was set in the configuration
public function canContinue()
Determine whether we can continue processing items in the queue.
public function poll()
Run a polling cycle during idle processing in the input loop.
protected function noHandlerFound(Queue_item $qi,  
 $rep = null)
OpportunisticQM shouldn’t discard items it can’t handle, we’re only here to take care of what we can handle!
protected function _fail(Queue_item $qi,  
 $releaseOnly = false)
Free our claimed queue item for later reprocessing in case of temporary failure.
public function runQueue()
Takes care of running through the queue items, returning when the limits setup in __construct are met.