Esempio n. 1
0
 /**
  * Spawns a new process for the Runnable_Interface
  *
  * @param \Multitask\Runnable_Interface $run           The Runnable_interface that needs to be run
  * @param String                        $workDirectory The current working directory
  *
  * @return int The pid of the spawned process
  */
 public function spawn(Runnable_Interface $run, $workDirectory)
 {
     $manager = $this->manager;
     $newWorkingDirectory = $workDirectory . '/' . $run->getName();
     return $this->process->spawn(function () use($run, $manager) {
         $run->run($manager);
     }, function () use($manager, $newWorkingDirectory) {
         $manager->initForNewProcess($newWorkingDirectory);
     }, function () use($manager) {
         $manager->postProcess();
     });
 }
Esempio n. 2
0
 public function addRunnable(\Multitask\Runnable_Interface $runnable, $pid)
 {
     $cacheItem = array('pid' => $pid, 'runnable' => $runnable, 'name' => $runnable->getName());
     $this->nameCache[$cacheItem['name']] = $cacheItem;
     $this->pidCache[$pid] = $cacheItem;
 }
Esempio n. 3
0
 /**
  * Runs a class that implements the Runnable interface
  * It checks if there is allready a process running iwith this name in the current process group
  *
  * @param Runnable_Interface $run            Runnable that you want to run
  * @param bool     $checkIfRunning check if the process is allready running if specified as false it won't check this is useful if you know the process isn't running
  * 
  * @return bool|int                the pid of the spawned or running process false with failure to spawn
  */
 public function run(Runnable_Interface $run, $checkIfRunning = true)
 {
     $pid = false;
     if ($checkIfRunning) {
         $pid = $this->fileHandler->get($this->workingDirectory, $run->getName() . '.pid');
         if (!$this->process->checkPidIsAlive($pid)) {
             $pid = false;
         }
     }
     if (!$pid) {
         $pid = $this->spawner->spawn($run, $this->workingDirectory);
     }
     if ($pid) {
         $this->addRunnableToCache($run, $pid);
     }
     return $pid;
 }