public function single($force=false)
    {
        // Pre-work check
        if (!method_exists($this, 'handleSingle'))
            throw new Exception("You need to declare `handleSingle()` method in your worker controller.", 500);

        // Shared lock flag builder
        $lockFile = sys_get_temp_dir() 
            . "/yidas-codeiginiter-queue-worker_" 
            . str_replace('/', '_', $this->router->fetch_directory()) 
            . get_called_class()
            . '.lock';

        // Single check for process uniqueness
        if (!$force && file_exists($lockFile)) {

            $lockData = json_decode(file_get_contents($lockFile), true);
            // Check expires time
            if (isset($lockData['expires_at']) && time() <= $lockData['expires_at']) {
                die("Single is already running: {$lockFile}\n");
            }
        }

        // Start Single - Set identified lock
        // Close Single - Release identified lock
        register_shutdown_function(function() use ($lockFile) {
            @unlink($lockFile);
        });

        // Create lock file
        $this->_singleUpdateLock($lockFile);

        // Call customized worker process, stops till catch false by callback return
        while ($this->handleSingle($this->_staticSingle)) {

            // Sleep if set
            if ($this->singleSleep) {
                sleep($this->singleSleep);
            }

            // Refresh lock file
            $this->_singleUpdateLock($lockFile);
        }
    }
public function single($force=false)
    {
        // Pre-work check
        if (!method_exists($this, 'handleSingle'))
            throw new Exception("You need to declare `handleSingle()` method in your worker controller.", 500);

        // Shared lock flag builder
        $lockFile = sys_get_temp_dir() 
            . "/yidas-codeiginiter-queue-worker_" 
            . str_replace('/', '_', $this->router->fetch_directory()) 
            . get_called_class()
            . '.lock';

        // Single check for process uniqueness
        if (!$force && file_exists($lockFile)) {

            $lockData = json_decode(file_get_contents($lockFile), true);
            // Check expires time
            if (isset($lockData['expires_at']) && time() <= $lockData['expires_at']) {
                die("Single is already running: {$lockFile}\n");
            }
        }

        // Start Single - Set identified lock
        // Close Single - Release identified lock
        register_shutdown_function(function() use ($lockFile) {
            @unlink($lockFile);
        });

        // Create lock file
        $this->_singleUpdateLock($lockFile);

        // Call customized worker process, stops till catch false by callback return
        while ($this->handleSingle($this->_staticSingle)) {

            // Sleep if set
            if ($this->singleSleep) {
                sleep($this->singleSleep);
            }

            // Refresh lock file
            $this->_singleUpdateLock($lockFile);
        }
    }
public function single ( $ force = false ) { // Pre-work check if ( ! method_exists ( $ this , 'handleSingle' ) ) throw new Exception ( "You need to declare `handleSingle()` method in your worker controller." , 500 ) ; // Shared lock flag builder $ lockFile = sys_get_temp_dir ( ) . "/yidas-codeiginiter-queue-worker_" . str_replace ( '/' , '_' , $ this -> router -> fetch_directory ( ) ) . get_called_class ( ) . '.lock' ; // Single check for process uniqueness if ( ! $ force && file_exists ( $ lockFile ) ) { $ lockData = json_decode ( file_get_contents ( $ lockFile ) , true ) ; // Check expires time if ( isset ( $ lockData [ 'expires_at' ] ) && time ( ) <= $ lockData [ 'expires_at' ] ) { die ( "Single is already running: {$lockFile}\n" ) ; } } // Start Single - Set identified lock // Close Single - Release identified lock register_shutdown_function ( function ( ) use ( $ lockFile ) { @ unlink ( $ lockFile ) ; } ) ; // Create lock file $ this -> _singleUpdateLock ( $ lockFile ) ; // Call customized worker process, stops till catch false by callback return while ( $ this -> handleSingle ( $ this -> _staticSingle ) ) { // Sleep if set if ( $ this -> singleSleep ) { sleep ( $ this -> singleSleep ) ; } // Refresh lock file $ this -> _singleUpdateLock ( $ lockFile ) ; } }
Action for activating a single listened worker

Single process ensures unique process running, which prevents the same

The reason which this doesn't use process check method such as `ps`, `pgrep`, is that the
process ID or name are unrecognizable as unique for ensuring only one Single process is
running.

@return void
Action for activating a single listened worker