Ejemplo n.º 1
0
 public function parse($arguments = null)
 {
     $optionsFromCommandLine = new Getopt\Getopt($this->addHelpOption(Onebip\array_map($this->options, function ($option) {
         return $option->specification();
     })));
     try {
         $optionsFromCommandLine->parse();
         if ($this->helpHasBeenAsked($optionsFromCommandLine)) {
             $this->showHelpAndExitWith($optionsFromCommandLine, 0);
         }
         foreach ($this->options as $key => $option) {
             $this->values[$key] = $option->pickFrom($optionsFromCommandLine);
         }
     } catch (UnexpectedValueException $e) {
         $this->showErrorMessageAndExit($e, $optionsFromCommandLine);
     }
     return $this;
 }
Ejemplo n.º 2
0
 public static function tryToAssignJobsToWorkers(MongoCollection $collection, $jobs, $workers)
 {
     $assignment = array_combine(Onebip\array_map($workers, function ($id) {
         return (string) $id;
     }), $jobs);
     $result = $collection->update($where = ['_id' => ['$in' => array_values($workers)]], $update = ['$set' => ['available' => false, 'assigned_to' => $assignment, 'assigned_since' => T\MongoDate::now()]], ['multiple' => true]);
     return [$assignment, $result['n']];
 }