Created
July 17, 2017 00:26
-
-
Save theMadness/1decef98db27c18c9cdea4af825e6c0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace DS\App\Console\Commands; | |
use DS\App\Models\ConciergeRssFeed; | |
use GuzzleHttp\Client; | |
use GuzzleHttp\Promise; | |
use GuzzleHttp\Psr7\Response; | |
use Illuminate\Console\Command; | |
class WebDataFetchCommand extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'app:web-fetch-data'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Retrieve and store the content of remote web resources'; | |
/** | |
* Execute the console command. | |
*/ | |
public function handle() | |
{ | |
$client = new Client([ | |
'timeout' => 20, | |
]); | |
$promises = []; | |
foreach (ConciergeRssFeed::all() as $feed) { | |
$promises[$feed->id] = $client->getAsync($feed->url)->then(function (Response $response) use ($feed) { | |
$feed->content = $response->getBody()->getContents(); | |
$feed->save(); | |
}); | |
} | |
Promise\settle($promises)->wait(); | |
$this->info('Data fetched'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment