All Projects → imTigger → Laravel Job Status

imTigger / Laravel Job Status

Licence: mit
Add ability to track Job progress, status and result dispatched to Queue.

Projects that are alternatives of or similar to Laravel Job Status

Laravel Gitscrum
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.
Stars: ✭ 2,686 (+862.72%)
Mutual labels:  laravel, laravel-framework
Exq
Job processing library for Elixir - compatible with Resque / Sidekiq
Stars: ✭ 1,218 (+336.56%)
Mutual labels:  job-queue, queue
Laravel User Activity
Monitor user activity easily!
Stars: ✭ 253 (-9.32%)
Mutual labels:  laravel, laravel-framework
Auth Tests
Always-current tests for Laravel's authentication system. Curated by the community.
Stars: ✭ 230 (-17.56%)
Mutual labels:  laravel, laravel-framework
Laravel Postal Code Validation
Worldwide postal code validation for Laravel and Lumen
Stars: ✭ 278 (-0.36%)
Mutual labels:  laravel, lumen
Laracrud
Laravel Code Generator based on MySQL Database
Stars: ✭ 238 (-14.7%)
Mutual labels:  laravel, laravel-framework
Qutee
PHP Background Jobs (Tasks) Manager
Stars: ✭ 63 (-77.42%)
Mutual labels:  job-queue, queue
Jikan Rest
The REST API for Jikan
Stars: ✭ 200 (-28.32%)
Mutual labels:  laravel, lumen
orkid-node
Reliable and modern Redis Streams based task queue for Node.js 🤖
Stars: ✭ 61 (-78.14%)
Mutual labels:  queue, job-queue
Redis Smq
A simple high-performance Redis message queue for Node.js.
Stars: ✭ 230 (-17.56%)
Mutual labels:  job-queue, queue
Laravel Auth
Laravel 8 with user authentication, registration with email confirmation, social media authentication, password recovery, and captcha protection. Uses offical [Bootstrap 4](http://getbootstrap.com). This also makes full use of Controllers for the routes, templates for the views, and makes use of middleware for routing. The project can be stood u…
Stars: ✭ 2,692 (+864.87%)
Mutual labels:  laravel, laravel-framework
yerbie
A blazing fast job queue built for ease of use and scalability
Stars: ✭ 16 (-94.27%)
Mutual labels:  queue, job-queue
Learn Laravel
Laravel 学习资料和开源项目集
Stars: ✭ 229 (-17.92%)
Mutual labels:  laravel, laravel-framework
Laravel Log Viewer
🐪 Laravel log viewer
Stars: ✭ 2,726 (+877.06%)
Mutual labels:  laravel, lumen
Wagonwheel
Offer an online version of your Laravel emails to users.
Stars: ✭ 224 (-19.71%)
Mutual labels:  laravel, laravel-framework
Honeydew
Job Queue for Elixir. Clustered or Local. Straight BEAM. Optional Ecto. 💪🍈
Stars: ✭ 670 (+140.14%)
Mutual labels:  job-queue, queue
Laravel Cheat Sheet
Additional resource for the Udemy Laravel Essentials course
Stars: ✭ 194 (-30.47%)
Mutual labels:  laravel, laravel-framework
Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (-29.03%)
Mutual labels:  laravel, laravel-framework
Bull
Premium Queue package for handling distributed jobs and messages in NodeJS.
Stars: ✭ 11,748 (+4110.75%)
Mutual labels:  job-queue, queue
celery.node
Celery task queue client/worker for nodejs
Stars: ✭ 164 (-41.22%)
Mutual labels:  queue, job-queue

Laravel Job Status

Latest Stable Version Total Downloads Build Status License

Laravel package to add ability to track Job progress, status and result dispatched to Queue.

  • Queue name, attempts, status and created/updated/started/finished timestamp.

  • Progress update, with arbitrary current/max value and percentage auto calculated

  • Handles failed job with exception message

  • Custom input/output

  • Native Eloquent model JobStatus

  • Support all drivers included in Laravel (null/sync/database/beanstalkd/redis/sqs)

  • This package intentionally do not provide any UI for displaying Job progress.

    If you have such need, please refer to laravel-job-status-progress-view

    or make your own implementation using JobStatus model

Requirements

  • PHP >= 7.1
  • Laravel/Lumen >= 5.5

Installation

Installation for Laravel

Installation for Lumen

Usage

In your Job, use Trackable trait and call $this->prepareStatus() in constructor.

<?php
namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Imtigger\LaravelJobStatus\Trackable;

class TrackableJob implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels, Trackable;

    public function __construct(array $params)
    {
        $this->prepareStatus();
        $this->params = $params; // Optional
        $this->setInput($this->params); // Optional
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $max = mt_rand(5, 30);
        $this->setProgressMax($max);

        for ($i = 0; $i <= $max; $i += 1) {
            sleep(1); // Some Long Operations
            $this->setProgressNow($i);
        }

        $this->setOutput(['total' => $max, 'other' => 'parameter']);
    }
}

In your Job dispatcher, call $job->getJobStatusId() to get $jobStatusId:

<?php

class YourController {
    use DispatchesJobs;

    function go() {
        $job = new TrackableJob([]);
        $this->dispatch($job);

        $jobStatusId = $job->getJobStatusId();
    }
}

$jobStatusId can be used elsewhere to retrieve job status, progress and output.

<?php
$jobStatus = JobStatus::find($jobStatusId);

Troubleshooting

Call to undefined method ...->getJobStatusId()

Laravel provide many ways to dispatch Jobs. Not all methods return your Job object, for example:

<?php
YourJob::dispatch(); // Returns PendingDispatch instead of YourJob object, leaving no way to retrive `$job->getJobStatusId();`

If you really need to dispatch job in this way, workarounds needed: Create your own key

  1. Create migration adding extra key to job_statuses table.

  2. In your job, generate your own unique key and pass into prepareStatus();, $this->prepareStatus(['key' => $params['key']]);

  3. Find JobStatus another way: $jobStatus = JobStatus::whereKey($key)->firstOrFail();

Status not updating until transaction commited

On version >= 1.1, dedicated database connection support is added.

Therefore JobStatus updates can be saved instantly even within your application transaction.

Read setup step 6 for instructions.

Documentations

<?php
// Job protected methods (Call from your Job)
$this->prepareStatus();                           // Must be called in constructor before any other methods
$this->setProgressMax(int $v);                    // Update the max number of progress
$this->setProgressNow(int $v);                    // Update the current number progress
$this->setProgressNow(int $v, int $every);        // Update the current number progress, write to database only when $v % $every == 0
$this->incrementProgress(int $offset)             // Increase current number progress by $offset
$this->incrementProgress(int $offset, int $every) // Increase current number progress by $offset, write to database only when $v % $every == 0
$this->setInput(array $v);                        // Store input into database
$this->setOutput(array $v);                       // Store output into database (Typically the run result)

// Job public methods (Call from your Job dispatcher)
$job->getJobStatusId();                       // Return the primary key of JobStatus (To retrieve status later)

// JobStatus object fields
var_dump($jobStatus->job_id);                 // String (Result varies with driver, see note)
var_dump($jobStatus->type);                   // String
var_dump($jobStatus->queue);                  // String
var_dump($jobStatus->status);                 // String [queued|executing|finished|retrying|failed]
var_dump($jobStatus->attempts);               // Integer
var_dump($jobStatus->progress_now);           // Integer
var_dump($jobStatus->progress_max);           // Integer
var_dump($jobStatus->input);                  // Array
var_dump($jobStatus->output);                 // Array, ['message' => $exception->getMessage()] if job failed
var_dump($jobStatus->created_at);             // Carbon object
var_dump($jobStatus->updated_at);             // Carbon object
var_dump($jobStatus->started_at);             // Carbon object
var_dump($jobStatus->finished_at);            // Carbon object

// JobStatus generated fields
var_dump($jobStatus->progress_percentage);    // Double [0-100], useful for displaying progress bar
var_dump($jobStatus->is_ended);               // Boolean, true if status == finished || status == failed
var_dump($jobStatus->is_executing);           // Boolean, true if status == executing
var_dump($jobStatus->is_failed);              // Boolean, true if status == failed
var_dump($jobStatus->is_finished);            // Boolean, true if status == finished
var_dump($jobStatus->is_queued);              // Boolean, true if status == queued
var_dump($jobStatus->is_retrying);            // Boolean, true if status == retrying

Note

$jobStatus->job_id result varys with driver

Driver job_id
null NULL (Job not run at all!)
sync empty string
database integer
beanstalkd integer
redis string(32)
sqs GUID
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].