New code for updated import routine.

This commit is contained in:
James Cole
2018-05-01 20:47:38 +02:00
parent cd75224cdd
commit ccda71ff8e
16 changed files with 262 additions and 97 deletions

View File

@@ -86,10 +86,10 @@ class JobStatusController extends Controller
*
* @return JsonResponse
*/
public function json(ImportJob $job): JsonResponse
public function json(ImportJob $importJob): JsonResponse
{
$json = [
'status' => $job->status,
'status' => $importJob->status,
];
return response()->json($json);
@@ -101,20 +101,34 @@ class JobStatusController extends Controller
* @return JsonResponse
* @throws FireflyException
*/
public function start(ImportJob $job): JsonResponse
public function start(ImportJob $importJob): JsonResponse
{
$importProvider = $job->provider;
// catch impossible status:
$allowed = ['ready_to_run'];
if (null !== $importJob && !in_array($importJob->status, $allowed)) {
Log::error('Job is not ready.');
session()->flash('error', trans('import.bad_job_status'));
return redirect(route('import.index'));
}
$importProvider = $importJob->provider;
$key = sprintf('import.routine.%s', $importProvider);
$className = config($key);
if (null === $className || !class_exists($className)) {
return response()->json(['status' => 'NOK', 'message' => sprintf('Cannot find import routine class for job of type "%s".', $importProvider)]);
}
// if the job is set to "provider_finished", we should be able to store transactions
// generated by the provider.
// otherwise, just continue.
// set job to be running:
$this->repository->setStatus($job, 'running');
$this->repository->setStatus($importJob, 'running');
/** @var RoutineInterface $routine */
$routine = app($className);
$routine->setJob($job);
$routine->setJob($importJob);
try {
$routine->run();
} catch (FireflyException $e) {
@@ -123,16 +137,13 @@ class JobStatusController extends Controller
Log::error($e->getTraceAsString());
// set job errored out:
$this->repository->setStatus($job, 'errored');
$this->repository->setStatus($importJob, 'error');
return response()->json(['status' => 'NOK', 'message' => $message]);
}
// set job finished this step:
$this->repository->setStatus($job, 'stage_finished');
// expect nothing from routine, just return OK to user.
return response()->json(['status' => 'OK', 'message' => 'finished']);
return response()->json(['status' => 'OK', 'message' => 'stage_finished']);
}
// /**