Download the PHP package projectsaturnstudios/consumption-engine without Composer

On this page you can find all versions of the php package projectsaturnstudios/consumption-engine. 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 consumption-engine

Consumption Engine

Opinionated Laravel package for consuming cleaned CSV extracts into your domain via queued jobs, event sourcing, and realtime progress events.

Designed to run on job queues (Horizon recommended). Consumption work is dispatched to a processing queue; realtime broadcast events ride a dedicated broadcasts queue; projectors use your event-sourcing queue. Your Horizon supervisors must listen to all three.

Quick start

  1. Install the package — use Option A or B under Install.
  2. Publish config + migration, then migrate.
  3. Define the source/audit disks in config/filesystems.php and point config/tasks.php at them.
  4. Configure Spatie / PSS event sourcing + Media Library (stored events, media tables, projector workers) — see Event sourcing dependencies.
  5. Register at least one task + ConsumptionJob in config/tasks.php.
  6. Start Horizon workers on data-proc (required for jobs + CLI progress), broadcasts (Echo), and your projector queue (e.g. EVENT_PROJECTOR_QUEUE_NAME).
  7. Run php artisan consume {task} or call ConsumptionEngine::executeTask().

php artisan consume listens for progress for 10 seconds of inactivity after the last update. Start the data-proc worker before running the command.

Requirements

Install

Option A — Packagist / VCS require

If transitive projectsaturnstudios/* packages are private VCS deps, add Bitbucket/GitHub repositories entries and Composer auth in the host app before requiring this package (or use Option B).

Option B — path repository (local monorepo)

Add this to the host app composer.json first:

Then:

Adjust the path URL if your package does not live under projectsaturnstudios/ relative to the host app.

The service provider is auto-discovered.

Publish config & migration

Publish the tasks config:

Publish the audit_logs migration:

Then migrate:

Configuration

Published file: config/tasks.php.

Source & audit disks

Both folder listing (FileStorageRepo) and CSV reads (ConsumptionJob) use config('tasks.disk'). Audit JSON writes use config('tasks.audit_disk') under /audits/{task}/....

Define those disk names in the host app before running consume. Example config/filesystems.php entries:

CSVs are read from {disk root}/{folder}/…. Audits are written to {audit_disk}/audits/{task}/….

Registering consumption jobs

Each task key maps a slug to a folder and a job class that extends ConsumptionJob:

Filenames must end with YYYY-MM-DD.csv (for example cp_2024-05-30.csv). The date is parsed from that trailing segment.

Queues & Horizon

This package is queue-first:

Concern Default queue Notes
Consumption jobs data-proc Dispatched by executeTask() / consume
Realtime broadcast events broadcasts ConsumptionRTEvent::$queue / broadcastQueue() — keep off the projector queue
Event-sourcing projectors EVENT_PROJECTOR_QUEUE_NAME Spatie / PSS projector workers (host-app env)

Without a data-proc worker, jobs never run and consume hits the 10s inactivity timeout. Without a broadcasts worker, Echo broadcasts stall — the CLI Redis list side-channel still works because RPUSH happens in the data-proc worker.

Example Horizon supervisors

Add (or merge) supervisors like these in the host app config/horizon.php defaults array:

Also reference each supervisor key under environments (for example local / staging / production). Horizon defaults alone does not start workers — and a missing APP_ENV key under environments boots zero supervisors.

Then:

Starting a task

Artisan

FileFinder builds {folder}/{filename} from the task config, so --file is the basename (or relative name under the folder), not the full storage key.

consume validates, dispatches the job, then listens on a Redis list key for progress until TaskCompleted, TaskFailed, or 10 seconds of inactivity.

Programmatically

executeTask() only validates and dispatches. For progress monitoring, subscribe via Echo (Artisan).

executeTask() returns TASK_STARTED on success. Other common returns: INVALID_TASK, INVALID_FILENAME, TASK_ALREADY_COMPLETED, TASK_PREVIOUSLY_FAILED, NO_MORE_TASKS_AVAILABLE. (READY is an internal validation gate only — callers never receive it.)

Creating a consumption job

Pipeline (handle())

  1. TaskInitializing
  2. setupAuditLog() — load CSV, key by uuid, seed empty audit entries, fire CreateAuditLogRecord, then TaskInitialized
  3. validateRecords(&$contents)
  4. setRecordActions(&$contents)
  5. updateRecords($contents) — optional; default no-op; runs before creates
  6. consumeNewRecords($contents)
  7. saveAuditLog()SavingAuditLog, then TaskCompleted or TaskFailed

UUID requirement

Every CSV row must be keyable by uuid. Either include a uuid column, or override getContents() to inject one before validation.

Implement the abstract methods

What belongs in each abstract method

Method Responsibility
validateRecords Schema/DTO validation; keep invalid rows out of the returned collection; seed audit status. Whatever you put in the collection (arrays or DTOs) is what later phases receive.
setRecordActions Diff against existing projections (your code); set action (create / update / none / …). Rows with none stay in the audit log but are skipped by update/create helpers.
updateRecords Optional. Apply update actions (usually via updateActionRecords(..., 'update', ...)). Runs before creates.
consumeNewRecords Apply create actions (usually via event_command(...) + your domain packages)

validateRecords and setRecordActions take the collection by reference — assign back when you replace it. consumeNewRecords / updateRecords do not.

audit_log contract

Helpers on the base class

Register the class under config/tasks.php as shown above.

Realtime / Echo events

Every progress event implements ShouldBroadcast and is published on a public channel:

Example: task catalog-products → channel consume-catalog-products.

The same string is also used as a Redis list key: events RPUSH JSON so php artisan consume can BLPOP without Echo. Echo uses the broadcast driver; the CLI uses the list. Same name, different mechanisms.

Host broadcasting setup (required for Echo only)

CLI progress does not need broadcasting. Browser UI does.

  1. Set BROADCAST_CONNECTION=reverb (or pusher) in the host .env.
  2. Configure Reverb/Pusher credentials (REVERB_APP_ID, REVERB_APP_KEY, REVERB_APP_SECRET, REVERB_HOST, …).
  3. Ensure a Horizon/broadcasts worker is running so broadcast jobs are processed.
  4. Initialize Laravel Echo in the frontend with the same app key/host, then subscribe as below.

Subscribe with Laravel Echo

Events define broadcastAs() as the short class basename. Listen with a leading dot:

Event When Fired by
TaskInitializing Job handle starts Base job (automatic)
TaskInitialized Audit log started / contents loaded Base job (automatic)
TaskDataValidationStarted Validation phase begins Your job via fireEvent()
TaskProgress Throttled percent progress Base helpers (automatic when used)
TaskUpdateConsumeStarted Update phase begins updateActionRecords()
TaskRecordConsumeStarted Create/consume phase begins consumeActionRecords()
SavingAuditLog Before audit JSON + finish command Base job (automatic)
TaskCompleted Happy path finished Base job after successful audit save
TaskFailed Exception during audit save Base job catch in saveAuditLog() only
TaskWarning Non-fatal row issues Your job via fireEvent()

Failure signaling: TaskFailed is emitted only when saveAuditLog() throws. Uncaught exceptions earlier in validateRecords / update / consume leave the CLI waiting until the 10s inactivity timeout (no terminal Redis event).

Dual payloads: Echo receives public event properties (pct, reason, warning, num_records, …). The Redis CLI payload params comes from toArray() and may omit those fields (for example pct / num_records). CLI listeners should rely on message + event class for terminal handling.

Broadcast jobs use the broadcasts queue — keep a Horizon worker on that queue for Echo.

Event sourcing dependencies

Domain audit lifecycle uses PSS Event Sourcing (projectsaturnstudios/pss-event-sourcing), which builds on Spatie Laravel Event Sourcing:

This package registers ConsumptionJobProjector automatically; it does not replace your host event-sourcing bootstrap.

Host checklist (minimum)

  1. Require the packages in the host app:

  2. Publish and run Spatie event-sourcing migrations / config (stored events table + config/event-sourcing.php) per Spatie’s docs.
  3. Publish and migrate Spatie Media Library tables (required for audit finish attachment).
  4. Ensure PSS helpers are available (event_command(), DataEvent) — normally via the PSS package service provider / autoload.
  5. Set the projector queue, for example:

  6. Run a worker that consumes that queue (see Queues & Horizon).
  7. Publish and migrate this package’s audit_logs table (see Publish config & migration).

If event sourcing is missing, CreateAuditLogRecord / LogConsumption fail when a job starts or finishes. If Media Library is missing, audit finish (addMediaFromDisk) fails after the JSON audit is written.

Testing

Pest unit tests live in this package (tests/Unit), not in the host application.

License

MIT


All versions of consumption-engine with dependencies

PHP Build Version
Package Version
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 projectsaturnstudios/consumption-engine contains the following files

Loading the files please wait ...