|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Created by PhpStorm. |
| 4 | + * User: dusanklinec |
| 5 | + * Date: 26/01/2018 |
| 6 | + * Time: 13:01 |
| 7 | + */ |
| 8 | + |
| 9 | +namespace ph4r05\LaravelDatabasePh4\Queue\Misc; |
| 10 | + |
| 11 | +/** |
| 12 | + * Class WorkersTracker |
| 13 | + * |
| 14 | + * Uses database table to track active workers currently working on the given queue. |
| 15 | + * Worker register itself to the DB when created, updates his record during the progress |
| 16 | + * and deletes the record when terminating. The periodic updating helps to detect |
| 17 | + * killed workers. |
| 18 | + * |
| 19 | + * The number of active workers per queue helps to optimize parameter setup for optimistic |
| 20 | + * queue locking. |
| 21 | + * |
| 22 | + * @package ph4r05\LaravelDatabasePh4\Queue\Misc |
| 23 | + */ |
| 24 | +class WorkerTracker |
| 25 | +{ |
| 26 | + /** |
| 27 | + * queue -> last ping time |
| 28 | + * @var array |
| 29 | + */ |
| 30 | + protected $lastPingMap = []; |
| 31 | + |
| 32 | + /** |
| 33 | + * queue -> active workers list |
| 34 | + * @var array |
| 35 | + */ |
| 36 | + protected $workersMap = []; |
| 37 | + |
| 38 | + public function __construct(){ |
| 39 | + // TODO: implement |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Updates the ping time for the given queue for the current worker. |
| 44 | + * Can do nothing if the last ping was too recent. |
| 45 | + * |
| 46 | + * @param $queue |
| 47 | + * @param $force bool - override caching, enforce db write |
| 48 | + */ |
| 49 | + public function tick($queue, $force = false){ |
| 50 | + // TODO: implement |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Creates the current worker records. Initial step when worker starts. |
| 55 | + * |
| 56 | + * @param $queues |
| 57 | + */ |
| 58 | + public function create($queues){ |
| 59 | + // TODO: implement |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Destroys records for the current worker. |
| 64 | + * Called when worker terminates. |
| 65 | + * |
| 66 | + * @param $queues |
| 67 | + */ |
| 68 | + public function destroy($queues){ |
| 69 | + // TODO: implement |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Returns number of workers active for the queue. |
| 74 | + * @param $queue |
| 75 | + */ |
| 76 | + public function getNumWorkers($queue){ |
| 77 | + // TODO: implement |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | +} |
| 82 | + |
| 83 | +/** |
| 84 | + * Class WorkerRecord |
| 85 | + * Helper wrapper for loading active workers. |
| 86 | + * @package ph4r05\LaravelDatabasePh4\Queue\Misc |
| 87 | + */ |
| 88 | +class WorkerRecord { |
| 89 | + |
| 90 | +} |
| 91 | + |
0 commit comments