Spaces:
Running
Running
File size: 1,994 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | <?php
namespace App\Services;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
class MdSimulationService
{
private string $baseUrl;
private int $timeout;
public function __construct()
{
$this->baseUrl = rtrim(config('services.md_simulation.url', 'http://protein-ligand-md:5005'), '/');
$this->timeout = (int) config('services.md_simulation.timeout', 3600);
}
public function submitJob(string $proteinPath, string $proteinName, string $ligandPath, string $ligandName, array $params): Response
{
$http = Http::timeout(120);
$http = $http->attach(
'protein',
fopen($proteinPath, 'r'),
$proteinName
);
$http = $http->attach(
'ligand',
fopen($ligandPath, 'r'),
$ligandName
);
return $http->post($this->baseUrl.'/process', $params);
}
public function getJobStatus(string $remoteJobId): Response
{
return Http::timeout(30)
->retry(3, 1000)
->get($this->baseUrl."/status/{$remoteJobId}");
}
public function runAnalysis(string $remoteJobId, array $params = []): Response
{
return Http::timeout($this->timeout)
->retry(3, 2000)
->post($this->baseUrl.'/analyze', array_merge($params, [
'job_id' => $remoteJobId,
]));
}
public function downloadResults(string $remoteJobId): Response
{
return Http::timeout($this->timeout)
->retry(2, 5000)
->get($this->baseUrl."/download/{$remoteJobId}");
}
public function downloadAnalysis(string $remoteJobId): Response
{
return Http::timeout($this->timeout)
->retry(2, 5000)
->get($this->baseUrl."/download_analysis/{$remoteJobId}");
}
public function healthCheck(): Response
{
return Http::timeout(10)->get($this->baseUrl.'/health');
}
}
|