Example #1
0
 /**
  * Execute the console command
  *
  * @return void
  */
 public function fire()
 {
     // Check for a list option
     $list = $this->option('list');
     $job_name = $this->argument('jobname');
     if (empty($list) && !empty($job_name)) {
         $inputController = new InputController();
         list($collection_uri, $name) = $inputController->getParts($job_name);
         // Check if the job exists
         $job = \Job::where('name', '=', $name)->where('collection_uri', '=', $collection_uri)->first();
         if (empty($job)) {
             $this->error("The job with identified by: {$job_name} could not be found.\n");
             exit;
         }
         $this->info('The job has been found.');
         // Configure a log handler if configured
         $this->addLogHandler();
         $startDate = new Carbon();
         $iso8601 = $startDate->toISo8601String();
         \Log::info("Executing job {$name} at {$iso8601}");
         try {
             $job_exec = new JobExecuter($job, $this);
             $job_exec->execute();
         } catch (\Exception $ex) {
             $endDate = new Carbon();
             $iso8601 = $endDate->toISO8601String();
             \Log::error("The job {$job_name} has failed at {$iso8601}");
             \Log::error($ex->getMessage());
             \Log::error($ex->getTraceAsString());
         }
         $endDate = new Carbon();
         $iso8601 = $endDate->toISO8601String();
         $job->date_executed = time();
         $job->added_to_queue = false;
         $job->save();
         \Log::info("The job has ended at {$iso8601}");
     } else {
         $jobs = \Job::all(['name', 'collection_uri'])->toArray();
         if (!empty($jobs)) {
             $this->info("=== Job names ===");
             foreach ($jobs as $job) {
                 $this->info($job['collection_uri'] . '/' . $job['name']);
             }
         } else {
             $this->info("No jobs found.");
         }
     }
 }
Example #2
0
File: Import.php Project: tdt/input
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     // Get the input file from the arguments, if none specified use the default file path from the export command
     $file = $this->argument('file');
     if (empty($file)) {
         $file = Export::getExportFile();
     }
     $safe = $this->option('safe');
     // Get the contents from the file if it exists
     if (\File::exists($file)) {
         $content = json_decode(\File::get($file), true);
         // If the content is legit, proceed to make the calls to the input endpoint
         if ($content) {
             foreach ($content as $identifier => $job_definition) {
                 // If the safe option is passed, prompt the user with the identifier and body
                 if ($safe) {
                     if (!$this->confirm("A job with identifier {$identifier} is about to be added, are you sure about this? [y|n]")) {
                         $this->info("The job with identifier {$identifier} was prevented of being added.");
                         break;
                     }
                 }
                 $this->updateRequest('PUT', array(), $job_definition);
                 $input_controller = new InputController();
                 $response = $input_controller->createJob($identifier);
                 $status_code = $response->getStatusCode();
                 if ($status_code == 200) {
                     $this->info("A new definition with identifier ({$identifier}) was succesfully added.");
                 } else {
                     $this->error("A status of {$status_code} was returned when adding {$identifier}, check the logs for indications of what may have gone wrong.");
                 }
             }
         } else {
             $this->error("We failed to extract the input jobs from the json, make sure the JSON content is valid.");
             die;
         }
     } else {
         $this->error("We couldn't find the file ({$file}) containing the input jobs, make sure the path is reachable for the datatank.");
         die;
     }
 }
Example #3
0
 /**
  * Execute the console command
  *
  * @return void
  */
 public function fire()
 {
     $job_name = $this->argument('jobname');
     list($collection_uri, $name) = InputController::getParts($job_name);
     // Check if the job exists
     $job = \Job::where('name', '=', $name)->where('collection_uri', '=', $collection_uri)->first();
     if (empty($job)) {
         $this->error("The job with identified by: {$job_name} could not be found.\n");
         exit;
     }
     $this->line('The job has been found.');
     $job_exec = new JobExecuter($job, $this);
     $job_exec->execute();
 }
Example #4
0
File: Export.php Project: tdt/input
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     // Get the file option from the command line
     $filename = $this->option('file');
     if (empty($filename)) {
         $filename = self::getExportFile();
     }
     // Get the jobid, if none is provided, return all of the jobs by default
     $jobid = $this->argument('jobid');
     $content = null;
     if (empty($jobid)) {
         $jobs = \Job::all();
         $content = array();
         foreach ($jobs as $job) {
             $content[$job->collection_uri . '/' . $job->name] = $job->getAllProperties();
         }
         $content = json_encode($content);
     } else {
         $job = InputController::get($jobid);
         if (empty($job)) {
             $this->error("No input job has been found with the given identifer ({$jobid}).");
             die;
         }
         $content[$job->collection_uri . '/' . $job->name] = $job->getAllProperties();
         $content = json_encode($content);
     }
     try {
         // Write to file
         $fs = new Filesystem();
         if ($fs->exists($filename)) {
             $fs->put($filename, $content);
         } else {
             $handle = fopen($filename, "w");
             if (!$handle) {
                 \App::abort('Could not open/create the file ' . $filename);
             }
             fwrite($handle, $content);
         }
         $this->info("The export has been written to the file '{$filename}'.");
     } catch (Exception $e) {
         $this->error("The contents could not be written to the file '{$filename}'.");
         die;
     }
 }
Example #5
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     // Get the file option from the command line
     $filename = $this->option('file');
     if (empty($file)) {
         $file = self::getExportFile();
     }
     // Get the jobid, if none is provided, return all of the jobs by default
     $jobid = $this->argument('jobid');
     $content = null;
     if (empty($jobid)) {
         $jobs = \Job::all();
         $content = array();
         foreach ($jobs as $job) {
             $content[$job->collection_uri . '/' . $job->name] = $job->getAllProperties();
         }
         $content = json_encode($content);
     } else {
         $job = InputController::get($jobid);
         if (empty($job)) {
             $this->error("No input job has been found with the given identifer ({$jobid}).");
             die;
         }
         $content[$job->collection_uri . '/' . $job->name] = $job->getAllProperties();
         $content = json_encode($content);
     }
     // Output
     if (empty($filename)) {
         // Print to console
         echo $content;
     } else {
         try {
             // Write to file
             file_put_contents($filename, $content);
             $this->info("The export has been written to the file '{$filename}'.");
         } catch (Exception $e) {
             $this->error("The contents could not be written to the file '{$filename}'.");
             die;
         }
     }
 }