Giter Club home page Giter Club logo

Comments (8)

liebig avatar liebig commented on July 21, 2024

Hi shiroamada, I had this question before so I will quote it:

Simplicity
The big goal is to create a simple central way to define cron jobs with Laravel. Creating cron jobs with Cron is simple because you use the Laravel route feature which you use for your application routing. In this route you have access to Laravels range of functions. You define a cron job simply by adding an expression together with the closure function which should be called.

Accessibility
The cron management start call can be exectued from the same machine where your Laravel is located (for example with crontab) or from everywhere on the internet (for example from a web cron service) - it is just a route call.

Centralisation
All cron managemant is centralised in a single route. You define all cron jobs in PHP and don't have to create many jobs in Linux crontab. Deactivating or removing a cron job is only a PHP function call.

Platform independency
Laravel is a great way to build small and big web applications. But not every application platform runs on a server which allows unix shell access. For this applications Cron provides an opportunity to define cron jobs by using external cron start requests.

Monitoring
To check if all cron jobs ran successfully, Cron logs each run and the run jobs to database and to Monolog. There will be application hooks in the near future to improve the monitoring functions, too.

My comfort zone
And at last, Cron is my personal way to manage my cron job scheduling. I am a web application developer, not an infrastructure guy. I like to handle things in PHP and not in the shell. I want to deploy my application to another server without worrying if I have access to crontab and other Linux tools. I really like Laravels routing functionality and don't like Laravel commands. They are really powerful but cron management should be easy and powerful as well. And finally, I love to handle things on a single point in my application without using the Linux shell or write a single PHP file for each job. Cron is the try to manage cron jobs without headaches.

So I hope you got an insight in the Cron philosophy. Just give Cron a try.

from cron.

shiroamada avatar shiroamada commented on July 21, 2024

ok, now I got a good understanding about this library. I think you should put this on your readme file :)

Thank you so much for your effort for doing. I am going to get my hand dirty to play your library!

**One more questions for the interval questions.
If your cron request crontab / third party cron service to call it. Why I need to set the interval? It is depend on the crontab when to call it. What is the usage for it?

From the log, I just see

[2014-04-04 16:24:42] development.ERROR: Cron run with manager id 5 is with 8 seconds between last run too fast.
or too late.

Is it just for the usage for log?

Lets say I got 2 cronjob, one is running every 15 minutes another is 60 minutes. two cronjob put together into one route. Will both task run? As you mentions in above statement
Centralisation
All cron managemant is centralised in a single route.

from cron.

liebig avatar liebig commented on July 21, 2024

Thank you for your feedback. I will add this to the README file.
Cron checks all runs, if they are in time. For this you need to set the interval you call the Route. This is only for logging and you can disable database logging with "Cron::setDatabaseLogging(false);" if you don't like it. With this functionality you can determine if a Route call wasn't executed.

So if you call this Route every 15 minutes and add the jobs "Cron::add('example1', '*/15 * * * *', function() {" and "Cron::add('example2', '0 * * * *', function() {", example 1 will run every minute and example2 every hour. Cron will check if the time has come and will execute the job.

from cron.

shiroamada avatar shiroamada commented on July 21, 2024
  1. Can I know what is the diff between cron_job & cron_manager in the database? I can't get any documentation between this table usage.

2.This is my coding in route:

            Cron::add('send1', '* * * * 1-5', function() {

            Log::info('Log for 1 minutes');
            return null;
        });
        Cron::add('send2', '*/2 * * * 1-5', function() {

            Log::info('Log for 2 minutes');
            return null;
        });

        // One job will be called
        $report = Cron::run(); 

I notice that the cron_manager keep added new ID.

and this is the log file

[2014-04-08 15:11:00] development.ERROR: Cron run with manager id 6 is with 341177 seconds between last run too late. [] []
[2014-04-08 15:11:00] development.INFO: The cron run with the manager id 6 was finished without errors. [] []
[2014-04-08 15:19:16] development.ERROR: Cron run with manager id 7 is with 497 seconds between last run too late. [] []
[2014-04-08 15:19:16] development.INFO: The cron run with the manager id 7 was finished without errors. [] []
[2014-04-08 15:24:58] development.ERROR: Cron run with manager id 8 is with 342 seconds between last run too late. [] []
[2014-04-08 15:24:58] development.INFO: The cron run with the manager id 8 was finished without errors. [] []
[2014-04-08 15:25:45] development.INFO: Cron run with manager id 9 is with 47 seconds between last run in time. [] []
[2014-04-08 15:25:45] development.INFO: The cron run with the manager id 9 was finished without errors. [] []
[2014-04-08 15:26:16] development.INFO: Cron run with manager id 10 is with 31 seconds between last run in time. [] []
[2014-04-08 15:26:16] development.INFO: The cron run with the manager id 10 was finished without errors. [] []
[2014-04-08 15:27:15] development.INFO: Cron run with manager id 11 is with 59 seconds between last run in time. [] []
[2014-04-08 15:27:15] development.INFO: The cron run with the manager id 11 was finished without errors. [] []
[2014-04-08 15:28:15] development.INFO: Cron run with manager id 12 is with 60 seconds between last run in time. [] []
[2014-04-08 15:28:15] development.INFO: The cron run with the manager id 12 was finished without errors. [] []
[2014-04-08 15:29:15] development.INFO: Cron run with manager id 13 is with 60 seconds between last run in time. [] []
[2014-04-08 15:29:15] development.INFO: The cron run with the manager id 13 was finished without errors. [] []
[2014-04-08 15:37:00] development.ERROR: Cron run with manager id 14 is with 465 seconds between last run too late. [] []
[2014-04-08 15:37:00] development.INFO: The cron run with the manager id 14 was finished without errors. [] []
[2014-04-08 15:47:01] development.INFO: Log for 1 minutes [] []
[2014-04-08 15:47:01] development.ERROR: Cron run with manager id 15 is with 601 seconds between last run too late. [] []
[2014-04-08 15:47:01] development.INFO: The cron run with the manager id 15 was finished without errors. [] []
[2014-04-08 15:49:01] development.WARNING: Lock file found - Cron is still running and prevent job overlapping is enabled - second Cron run will be terminated. [] []
[2014-04-08 15:49:01] development.INFO: Log for 1 minutes [] []
[2014-04-08 15:49:01] development.ERROR: Cron run with manager id 16 is with 120 seconds between last run too late. [] []
[2014-04-08 15:49:01] development.INFO: The cron run with the manager id 16 was finished without errors. [] []
[2014-04-08 15:50:00] development.INFO: Log for 1 minutes [] []
[2014-04-08 15:50:00] development.INFO: Log for 2 minutes [] []
[2014-04-08 15:50:00] development.INFO: Cron run with manager id 18 is with 59 seconds between last run in time. [] []
[2014-04-08 15:50:00] development.INFO: The cron run with the manager id 18 was finished without errors. [] []
  1. Can I have seperate log file instead of putting in storage/logs/laravel.log ? It is helping me to track the cron log also.

Thank you for reading it. I am really would like to use it.

from cron.

liebig avatar liebig commented on July 21, 2024

Hi shiroamada,

the README file is a documentation for how you use Cron. It has no information about the implementation. If you are interested in this, please have a look at the source files. They are well commented and they use PHPDoc syntax. In general for each Cron run command call one cron_manager entry will be created and for each job execution in this Cron run a cron_job entry will be added to the database.

Cron supports custom Monolog logger objects, please have a look at the documentation: https://github.com/liebig/cron#setlogger. You can disable the Laravel logging with Cron::setLaravelLogging(false). So have fun.

Your log file looks good. You got the error messages, because you don't call the Cron run method in the defined interval. You got the lock file warning, because you call the route twice and the first call wasn't finished. Overlapping is disabled by default.

If you have no further questions, please close this issue.

Thank you
Marc

from cron.

shiroamada avatar shiroamada commented on July 21, 2024

Hi Marc,

Thank you for your reply. I am still very new in laravel, if you can guide me on this, I would be appreciated.

  1. I checked my database the cron_job table did not added any record, but the cron_manager keep added new record.
  2. I had added Cron::setLogger(new \Monolog\Logger('cronLogger')); to my code as below:
Cron::setLogger(new \Monolog\Logger('cronLogger'));
        Cron::add('send1', '* * * * 1-5', function() {

            Log::info('Log for 1 minutes');
            return null;
        });
        Cron::add('send2', '*/2 * * * 1-5', function() {

            Log::info('Log for 2 minutes');
            return null;
        });

        // One job will be called
        $report = Cron::run();

But inside storage/logs/ still only showed laravel.log, I didn't see any cronLogger.log file?

  1. I don't understand the log file, why the manager id keep increasing. Keep time I refresh it, the ID will added one, my understanding they should be always the same, I am thinking that the cron job keep register the cron::add as a new job. It suppose the same?

Sorry for so many question about it.

from cron.

liebig avatar liebig commented on July 21, 2024

Hi shiroamada,

okay let's go on. The cron_job has no entries, because by default only error jobs will be logged to database. An error job is a job which does not return null. So let's change your send1 or send2 job and return for example the string "Whoops!". If you want to log all jobs to databse have a look at the README file https://github.com/liebig/cron#logonlyerrorjobstodatabase.

Adding just a new Monolog Logger object to Cron will not work. You have to add a handler to the Monolog object to write the logfile on file system, database or anything else. I will not support Monolog so please use Google (e.g. https://coderwall.com/p/o2-kng) or read the official documentation (https://github.com/Seldaek/monolog).

For each Cron run command call (every time you call the page with your browser and with the defined route) a new manager will be created. I don't understand why this is wondering you. Every database entry should have a primary key like this id. Please have look at the source files if you have any questions about the implementation.

I don't earn any money for developing or supporting Cron. I enjoy this in my free time but I expect from you, that you read the complete README file.

Thank you
Marc

from cron.

shiroamada avatar shiroamada commented on July 21, 2024

Hi Marc,

Thank you so much for your reply. I really appreciate for your work. I also in the way to learn laravel, I will look into your source code and study what is really happen behind. Well Done!

from cron.

Related Issues (20)

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.