/** * Executes the command cron:run. * * Tries to acquire the cron lock, then if no argument has been given runs all ready cron tasks. * If the cron lock can not be obtained, an error message is printed * and the exit status is set to 1. * If the verbose option is specified, each start of a task is printed. * Otherwise there is no output. * If an argument is given to the command, only the task whose name matches the * argument will be started. If verbose option is specified, * an info message containing the name of the task is printed. * If no task matches the argument given, an error message is printed * and the exit status is set to 2. * * @param InputInterface $input The input stream used to get the argument and verboe option. * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. * * @return int 0 if all is ok, 1 if a lock error occured and 2 if no task matching the argument was found. */ protected function execute(InputInterface $input, OutputInterface $output) { if ($this->lock_db->acquire()) { $task_name = $input->getArgument('name'); if ($task_name) { $exit_status = $this->run_one($input, $output, $task_name); } else { $exit_status = $this->run_all($input, $output); } $this->lock_db->release(); return $exit_status; } else { $output->writeln('<error>' . $this->user->lang('CRON_LOCK_ERROR') . '</error>'); return 1; } }
/** * Acquires a lock on the item table * * @return bool True if the lock was acquired, false if it has been acquired previously * * @throws \RuntimeException If the lock could not be acquired */ protected function acquire_lock() { if ($this->lock->owns_lock()) { return false; } if (!$this->lock->acquire()) { throw new \RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } return true; }