laravel-rabbitmq/producer/app/Jobs/ScreenshotJob.php

42 lines
937 B
PHP

<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Artisan;
class ScreenshotJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $process;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
$process = 'process' . random_int(1, 3);
$this->process = $process;
$this->onQueue($process);
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
file_put_contents(
public_path('pupeteer/' . time() . '.jpg'),
file_get_contents('http://puppeteer:4000?url=' . env('PUPPETEER_URL'))
);
}
}