Download the PHP package sammyjo20/laravel-chunkable-jobs without Composer

On this page you can find all versions of the php package sammyjo20/laravel-chunkable-jobs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-chunkable-jobs

# Laravel Chunkable Jobs ![Build Status](https://github.com/sammyjo20/laravel-chunkable-jobs/actions/workflows/tests.yml/badge.svg)

This package allows you to split up a process into multiple jobs with their own chunk. This is perfect for processing lots of data as you can delegate the processing into separate jobs or if you are retrieving data from a paginated API. It works by processing the job and then queueing another job to process the next chunk until it reaches the end.

Example

Installation

Install the package through Composer. This package requires PHP 8.1+ and Laravel 8 or higher.

Getting Started

Create a new job and remove the handle method from the job. Next, extend the ChunkableJob class. You will be required to add two methods to your class, a defineChunk method and handleChunk method. In my example, I will be fetching every Pokemon from the Pokemon API and storing it into my application. You should have something like the following.

Next, we’ll need to define our chunk, this tells the chunkable job how many items it has to process and the size of the chunks so it knows how many times to run the “handleChunk” method. Inside of this method, you can return a chunk. This chunk accepts three arguments: totalItems , chunkSize and startingPosition . If you return null or a chunk without any totalItems, handleChunk will not be processed.

Chunk Constructor

Next, we’ll want to write the logic to process each chunk. In my example, I want to make an API call for that chunk and then store the response. The handleMethod will be executed on every chunk and will contain useful information about the chunk.

Chunk Properties

Chunk Methods

Dispatching

To dispatch a chunkable job, it's exactly the same. The default behaviour of chunkable jobs is to process one job, then dispatch the next after it has been successfully processed.

Dispatching every chunked job at once

Sometimes you may want to throw as much resource as you can to a specific chunked job. If processing one chunk at a time is not suitable and you would rather dispatch every chunk straight away, you can use the dispatchAllChunks static method on the chunkable job. It will accept constructor arguments through the parameters. Alternatively, you can use the BulkChunkDispatcher class.

Stopping Chunking Early

Sometimes you might want to stop the chunking process early. You can use the stopChunking method and the job won’t dispatch the next chunk.

Customising The Starting Chunk

Sometimes you might want to resume a chunkable job where it may have failed previously or paused. You can set the chunk on the job instance before you dispatch the job.

Using ChunkRange to iterate over all chunks

If you need to iterate over every chunk, you can use the ChunkRange class. This will return a generator that you can iterate over to get every chunk.

Unknown Size Chunking

Sometimes you might not know the size/limit that you want to chunk for and therefor you want to keep chunking infinitely and stop when you know when you have reached a limit. If you would like to do this, you can use the UnknownSizeChunk which will set the size to PHP_MAX_INT (which is a really really big number) and you can stop when you like.

Setting the next chunk

Sometimes you might want to change the chunking entirely, if you would like to do this, you can use the nextChunk method when chunking and the next chunk will be replaced by this chunk.

SetUp & TearDown

The setUp and tearDown methods are called before and after the chunking process. This is useful if you need to do some setup before the chunking starts and some cleanup after all the job chunks have finished processing.

Warning around properties

When you use the ChunkableJob class on your job, you have to be careful about the properties that you set on your jobs during runtime. When the every next chunkable job is created, the current object is cloned including its public, protected and private properties. If there are any properties that are set by the defineChunk or handleChunk methods, and you do not want them to be shared with the next chunk, make sure to add the property to the $ignoredProperties array on the job.

Since private properties cannot be ignored, you should use the modifyClone method which can be used to unset private properties or make final adjustments to the cloned object before it is put onto the queue.

Support This Project

Buy Me a Coffee at ko-fi.com


All versions of laravel-chunkable-jobs with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sammyjo20/laravel-chunkable-jobs contains the following files

Loading the files please wait ....