Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammyjo20 authored Sep 18, 2022
1 parent 29b3103 commit 6fec17b
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,34 @@ This package allows you to split up a process into multiple jobs with their own

## Example

```bash
Todo
```php
<?php

use Sammyjo20\LaravelHaystack\Chunk;
use Sammyjo20\LaravelHaystack\ChunkableJob;

class GetPageOfPokemon extends ChunkableJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public function defineChunk(): ?Chunk
{
$response = Http::asJson()->get('https://pokeapi.co/api/v2/pokemon');

$count = $response->json('count'); // 1154

return new Chunk(totalItems: $count, chunkSize: 1, startingPosition: 1);
}

protected function handleChunk(Chunk $chunk): void
{
$response = Http::asJson()->get(sprintf('https://pokeapi.co/api/v2/pokemon?limit=%s&offset=%s', $chunk->limit, $chunk->offset));

$data = $response->json();

// Store data of response
}
}
```

## Installation
Expand Down

0 comments on commit 6fec17b

Please sign in to comment.