62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\RequestOptions;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use App\Utils\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SyncReportTaskDatabase implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
public $tries = 1;
|
|
protected $data;
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($data)
|
|
{
|
|
$this->data = $data;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
$token = config('app.task_token');
|
|
$url = env('APP_TASK_URL')."/api/tp/task/databases";
|
|
|
|
$client = new Client();
|
|
$header = [
|
|
'APPTOKEN' => $token,
|
|
'Content-Type' => 'application/json'
|
|
];
|
|
$options = [
|
|
RequestOptions::TIMEOUT => 3,
|
|
RequestOptions::HTTP_ERRORS => false,
|
|
RequestOptions::HEADERS => $header,
|
|
RequestOptions::QUERY => $this->data,
|
|
];
|
|
$response = $client->post($url, $options);
|
|
$content = $response->getBody();
|
|
$res = json_decode($content, true);
|
|
if ($res && isset($res['code'])) {
|
|
if ($res['code']) {
|
|
throw new \Exception($res['message']);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|