-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

A bit late, but, you should just use jsPull with the persistentNamespace.
...................................
:  ___   _   ___ ___ ___ _ ___    :
: |   \ /_\ / __| _ \ _ (_)   \   :
: | |) / _ \\__ \  _/   / | |) |  :
: |___/_/:\_\___/_| |_|_\_|___/   :
:........:........................:
: Web    : http://www.dasprids.de :
: E-mail : m...@dasprids.de       :
: Jabber : jab...@dasprids.de     :
: ICQ    : 105677955              :
:........:........................:


Ryan Brooks schrieb:
> Howdy folks, 
> 
> I have to confess that I am truly pleased with Zend_ProgressBar. However, I
> had a couple thoughts once I actually started using it. I am sending this
> message to the mailing list because I'm not entirely sure it is within the
> scope/context of Zend_ProgressBar.
> 
> I wonder if it's not a good idea to allow single instances of ZPB
> (namespaces). For instance, in my case I'm doing a search index rebuild of
> a large resultset. In particular I flush my index tables, fetch all my
> records and insert the index values into one table and the relations to
> another.
> 
> However, I'd like this process to be running a single instance at a time.
> For example, if I request /resource/intense/rebuild-search-index/, the
> process will start. However, if I request it again, I'd like the process to
> not start again, but update with the current progress. I had already
> considered adjusting Zend_ProgressBar::$_min to use
> Zend_ProgressBar::$_current as an offset, but in this particular case I
> don't think it applies. I'm including some code as an example.
> 
> One caveat I can think of is sharing process information across
> sessions/users, so it may be a good idea to pass in a cache object, or
> explicitly define a cache prefix? I also don't think this would be
> considered adapter functionality, as it seems fairly global to
> Zend_ProgressBar.
> 
> Other potential usage scenarios would be converting a video from one type
> to another, or converting a CMYK image to RGB (using a filename as a
> prefix), etc. 
> 
> The methods I propose (though their functionality, names and usage aren't
> in stone, I leave that to the devs) include:
> 
> setSingleInstance() // sets ZPB to allow a single instance of a progress
> bar, cross user
> setCacheInstance() // Either setting a Zend_Cache instance, or just a
> namespace
> setIgnoreUserAbort() // sets ignore_user_abort() - just a thought, not sure
> if it is needed
> isIdle() // Returns (bool) where singleInstance is registered (but not
> running?)
> isRunning() // returns (bool) if running
> getCurrent() // Current record convenience method
> removeCache() // flushes the cache object
> rewind() // Potentially not the best method name, but it would flush the
> cache, reset user abort, etc.
> 
> Just let me know if I'm out of my mind!
> 
> Thanks folks,
> 
> -Ryan
> 
> <?php
> require_once 'Zend/ProgressBar.php'; 
> require_once 'Zend/ProgressBar/Adapter/JsPush.php';
> class Resource_IntenseController extends My_Controller
> {
>       private $_cacheObj = NULL;
>       public function init()
>       {
>               $frontendOptions = array('automatic_serialization' => true);
>               $backendOptions  = array(
>                       'cache_dir' => 'cache/progressbar',
>                       'file_name_prefix' => 'myNamespace'
>               );
>               $this->_cacheObj = Zend_Cache::factory('Core', 'File', 
> $frontendOptions,
> $backendOptions);
>       }
>       private function _exampleRecordList()
>       {
>               if(!$records = $this->_cacheObj->load('index_process'))
>               {
>                       $records =
> IndexFactory::getInstance()->fetchLargeResultsetForReindexing('*');
>                       $this->_cacheObj->save($records, 'index_process');
>               }
>               return $records;
>       }
>       public function indexAction()
>       {
>               // ...
>       }
>       public function rebuildSearchIndexAction()
>       {
>               $this->noRender();
>               if (isset($_GET['progress']))
>               {
>                       $rows = $this->_exampleRecordList();
>                       $cnt = count($rows);
>                       $adapter     = new
> Zend_ProgressBar_Adapter_JsPush(array('updateMethodName' =>
> 'Zend_ProgressBar_Update', 'finishMethodName' =>
> 'Zend_ProgressBar_Finish')); 
>                       $progressBar = new Zend_ProgressBar($adapter, 0, $cnt, 
> 'index_Process');
> 
>                       $progressBar->setSingleInstance('my_namespace') // Or 
> true, and use
> _persistenceNamespace as a namespace adapter. It would allow single
> instances of multiple namespaces
>                               ->setCacheInstance($this->_cache)
>                               ->setIgnoreUserAbort();
>                       try
>                       {
>                               if($progressBar->isIdle() === (bool) TRUE)
>                               {
>                                       do {
>                                               $runningStatus = 
> $progressBar->isRunning();
>                                               $currentRecord = 
> $rows[$progressBar->getCurrent()];
>                                               
> Records_IndexFactory::getInstance()->insertSearchIndex($currentRecord,
> 'my_large_search_index');
>                                               $text = "Starting record 
> $currentRecord of $cnt";
>                                               
> $progressBar->update($currentRecord, $text); 
>                                               usleep(100000);
>                                       } while($runningStatus);
>                                       $progressBar->finish()
>                                               ->removeCache();
>                               }
>                       }
>                       catch(Exception $e)
>                       {
>                               $progressBar->rewind();
>                       }
>               }
>       }
> }
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmxmyoACgkQ0HfT5Ws789CfXQCfSk5VgwzyCRH0r1vcNiaEAB7/
2J8AoJvXrY83PG9noYQGIwIAkYiLCJDa
=iPfa
-----END PGP SIGNATURE-----

Reply via email to