File size: 1,325 Bytes
907b200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

namespace App\Jobs;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;

class RunTargetLookupJob implements ShouldQueue
{
    use Queueable;

    public function __construct(protected \App\Models\TargetLookup $targetLookup) {}

    public function handle(\App\Services\ScreeningService $screeningService): void
    {
        $this->targetLookup->update(['status' => 'processing']);

        try {
            $input = $this->targetLookup->input ?? [];
            if (empty($input['disease_name'])) {
                throw new \Exception('Disease name not found in input');
            }

            $output = $screeningService->getTargets($input);

            if (is_array($output)) {
                unset($output['warnings']);
            }

            $this->targetLookup->update([
                'output' => $output,
                'status' => 'completed',
            ]);
        } catch (\Exception $e) {
            \Illuminate\Support\Facades\Log::error('Target lookup job failed', [
                'id' => $this->targetLookup->id,
                'error' => $e->getMessage()
            ]);

            $this->targetLookup->update([
                'status' => 'failed',
                'output' => ['error' => $e->getMessage()],
            ]);
        }
    }
}