Giter VIP home page Giter VIP logo

jobrunningchecker's Introduction

JobRunningChecker - A Laravel Job

Run a callback and/or fire an event just after a job or a list of jobs of the same class have finished

Sometimes you have to split the task in many jobs and you need to know when that list has finished in order to run another task. It could be a bit tricky but thanks to this Class you can add a callback or an event to be run just after the job/jobs have been completed.

What does the JobRunningChecker class actually do?

This class performs a db query looking for a provided text. That text can be the fully qualified job class name you want to know if has finished or even any property data that belongs to that job. If that text is found, JobRunningChecker will dispatch itself and perform the same check. Once it's not found it means the job or jobs list has finished so it's time to run the callback and fire the event.

How to use it

Copy the JobRunningChecker Class into you app\Jobs folder.

Keep in mind that the default namespace for this Class is App\Jobs so if you would like to place the Class under another folder you have to update the namespace.

namespace App\Jobs;

Usage samples

Run a callback:

dispatch(new JobRunningChecker('TEXT-TO-SEARCH',function(){
            //Your Code which will be run just after the searched job has finished
        }));

Remember 'TEXT-TO-SEARCH' can be the fully qualified job class name or any other text that is contained by the job (property value,etc).

Fire an event:

dispatch(new JobRunningChecker('TEXT-TO-SEARCH',null,EventName::class);

Run a callback and fire an event:

dispatch(new JobRunningChecker('TEXT-TO-SEARCH',function(){
            //Your Code which will be run just after the searched job has finished
        }),EventName::class);

You can also pass a sleep time to make it wait till the next itself call:

dispatch(new JobRunningChecker('TEXT-TO-SEARCH',function(){
            //Your Code which will be run just after the searched job has finished
        }),EventName::class,5);

In the above sample it will wait for 5 seconds till dispatching itself.

Limitations

For now, It only works when you have set the queue driver to database.

Thanks to

Laravel

SuperClosure

jobrunningchecker's People

Contributors

edujugon avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.