Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Long Running Tasks Laravel Package

spatie/laravel-long-running-tasks

Monitor and poll external long-running jobs (e.g., AWS Rekognition) in Laravel. Define a task with a check() method that runs on a configurable interval, store meta/context, and automatically reschedule until it reports completion.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Polling-Based External Task Monitoring: The package excels at monitoring asynchronous, externally triggered tasks (e.g., AWS Rekognition, file processing APIs, or third-party webhooks) where polling is required. It abstracts the complexity of retry logic, status tracking, and timeouts, aligning well with eventual consistency patterns.
  • Laravel Ecosystem Integration: Leverages Laravel’s queue system (e.g., Redis, database, SQS) and Eloquent models, making it a natural fit for Laravel applications. The package’s design assumes a queue-backed workflow, which is idiomatic for Laravel.
  • Stateful Task Tracking: The LongRunningTaskLogItem model provides auditability (status, exceptions, run count) and recovery (retries, backoff strategies), which is critical for long-running processes where failures are inevitable.
  • Extensibility: Supports custom models, jobs, and strategies, allowing TPMs to adapt it to domain-specific needs (e.g., adding SLA tracking or custom metadata).

Integration Feasibility

  • Low Friction for Laravel Apps: Requires only composer install, migrations, and minimal config changes. The API is fluent and intuitive (e.g., MyTask::make()->meta($data)->start()), reducing onboarding time.
  • Queue Dependency: Mandatory for functionality. If the app doesn’t use queues, this becomes a blocker (though the package could theoretically work with sync processing, it’s not recommended).
  • Database Schema: Adds a single table (long_running_task_log_items) with minimal overhead. No complex joins or migrations are required beyond the provided ones.
  • Testing: Includes CI/CD checks (PHPStan, tests) and a well-documented README, easing validation of compatibility with existing codebases.

Technical Risk

  • Queue Bottlenecks: If tasks are high-frequency or CPU-intensive, the queue could become a single point of failure (e.g., Redis memory limits, worker starvation). Mitigation: Use dedicated queues or horizontal scaling (e.g., multiple queue workers).
  • External API Dependencies: Tasks are blocked by external service SLAs. For example, if AWS Rekognition has a 5-minute timeout, the package’s keep_checking_for_in_seconds must be shorter to avoid didNotComplete false positives.
  • State Management: The meta field is a serialized array, which may not suit complex data structures (e.g., nested objects, closures). Workaround: Use JSON encoding or a separate database table.
  • Backoff Strategies: The default backoff (e.g., StandardBackoffCheckStrategy) may not align with all external APIs. For example, some APIs require exponential backoff with jitter, which would need a custom strategy.
  • Error Handling: Exceptions in check() are caught and logged, but no built-in alerts (e.g., Slack, PagerDuty) are triggered. Requires additional integration (e.g., Laravel Horizon events or custom observers).

Key Questions for TPM

  1. Queue Infrastructure:
    • Is the app’s queue system scalable for long-running tasks? (e.g., Can Redis handle 10K+ tasks in flight?)
    • Are there SLA requirements for task completion? If so, how does the package’s keep_checking_for_in_seconds align with them?
  2. External API Constraints:
    • What are the timeout and retry limits of the external service? Does the package’s backoff strategy need customization?
    • Are there rate limits (e.g., AWS API calls per second)? If so, how will the package’s polling frequency be throttled?
  3. Monitoring and Observability:
    • How will task status and failures be surfaced to stakeholders? (e.g., Dashboard, alerts, logs)
    • Are there SLOs for task completion? If so, how will the package’s metrics (e.g., run_count, attempt) be used to track them?
  4. Failure Recovery:
    • What’s the RTO/RPO for failed tasks? Does the package’s onFailure method suffice, or is a custom retry policy needed?
    • Are there idempotency requirements for external API calls? The package doesn’t handle this natively.
  5. Performance:
    • What’s the expected volume of concurrent tasks? Will the database become a bottleneck for LongRunningTaskLogItem queries?
    • Are there memory constraints for tasks that process large payloads (e.g., video transcoding)? The package doesn’t offload work to workers—it only polls.
  6. Extensibility Needs:
    • Does the app need custom fields in the log model? If so, how will they be populated (e.g., via meta or events)?
    • Are there non-polling use cases (e.g., webhook-triggered tasks)? The package is polling-only; alternatives like Laravel’s ShouldQueue or Horizon may be needed.

Integration Approach

Stack Fit

  • Laravel Core: Native fit for Laravel 10.x (tested). Uses Eloquent, queues, and jobs, which are first-class citizens in Laravel.
  • Queue Drivers:
    • Redis/SQS: Best for scalability (supports delayed jobs, retries).
    • Database: Works but not recommended for high-volume tasks (locking overhead).
    • Sync: Avoid—blocks the request thread; use only for testing.
  • Database: MySQL/PostgreSQL (Eloquent-supported). No schema changes beyond the provided migration.
  • Observability:
    • Laravel Horizon: Can be used to monitor queue jobs (e.g., RunLongRunningTaskJob).
    • Custom Logging: Extend LongRunningTaskLogItem or use Laravel’s logging channels to track task lifecycle.
  • Testing:
    • Unit Tests: Mock LongRunningTask and LongRunningTaskLogItem for isolated testing.
    • Integration Tests: Use Laravel’s Queue::fake() to verify task polling behavior.

Migration Path

  1. Assessment Phase:
    • Audit existing long-running processes (e.g., cron jobs, external API polling).
    • Identify candidate tasks for migration (e.g., AWS Rekognition, file processing).
  2. Proof of Concept (PoC):
    • Implement a single task (e.g., VideoTranscodingTask) to validate:
      • Polling frequency aligns with external API SLAs.
      • Queue performance under load.
      • Error handling meets recovery needs.
  3. Incremental Rollout:
    • Phase 1: Migrate non-critical tasks (e.g., background reports).
    • Phase 2: Replace custom polling scripts with the package.
    • Phase 3: Extend for critical paths (e.g., payment processing).
  4. Configuration:
    • Publish and customize config/long-running-tasks.php (e.g., queues, backoff strategies).
    • Set up database monitoring for long_running_task_log_items growth.

Compatibility

  • Laravel Version: Tested on 10.x; may work on 9.x but not officially supported.
  • PHP Version: 8.1+ (due to Laravel 10.x requirements).
  • Dependencies:
    • Queue Drivers: Must support delayed jobs (Redis/SQS recommended).
    • Database: Must support Eloquent (MySQL/PostgreSQL/SQLite).
  • Conflicts:
    • Naming Collisions: The LongRunningTaskLogItem model could conflict with existing models. Mitigation: Use the log_model config to point to a custom model.
    • Queue Job Conflicts: The RunLongRunningTaskJob could clash with custom jobs. Mitigation: Rename or namespace the job.

Sequencing

  1. Prerequisites:
    • Ensure queues are configured and workers are running (php artisan queue:work).
    • Set up database backups before running migrations.
  2. Installation:
    • composer require spatie/laravel-long-running-tasks
    • php artisan vendor:publish --tag="long-running-tasks-migrations"
    • php artisan vendor:publish --tag="long-running-tasks-config"
    • php artisan migrate
  3. Development:
    • Create a base task class (e.g., App\Tasks\BaseLongRunningTask).
    • Implement 1–2 tasks in a feature branch.
    • Write unit/integration tests for task logic.
  4. Deployment:
    • Deploy to staging and monitor queue performance.
    • Gradually replace legacy polling with the package.
    • Set up **alert
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata