Git Product home page Git Product logo

Comments (8)

liebig avatar liebig commented on July 24, 2024

I like your idea and this will make Cron easier to use. It is difficult to generate a token and write it into a config file. You need write access and writing a value to a specific position in a file is no fun with php. If Cron is used with an external service, in most cases you can only define the url you call, not the post values or other things (like headers). So we can only use the url with all get parameters to secure the call. I would prefer to use the route only.

Because a generated long route definition could potentially crash with other definitions, I would recommend to let the Cron user define this route in the Cron config file. Maybe we can offer a command which generates a long route string (but does not write it into the config file).

So the steps to use Cron would be to install it, activate the route and/or command function in the config file and maybe set the route string for Cron. Now you can define the jobs in the start/global.php or start/develop.php if this environment is defined. What do you think about that?

from cron.

ameenross avatar ameenross commented on July 24, 2024

It is difficult to generate a token and write it into a config file. You need write access and writing a value to a specific position in a file is no fun with php.

I was hoping there was some kind of Laravel function to hook into, which takes care of it. I haven't found it if it exists though.

So we can only use the url with all get parameters to secure the call. I would prefer to use the route only.

Yes, Drupal does it with a GET parameter, here's an example from their docs: http://www.example.com/cron.php?cron_key=0MgWtfB33FYbbQ5UAC3L0LL3RC0PT3RNUBZILLA0Nf1Re (heh, I only just noted that this cron_key is not entirely random).

If we were to use a GET parameter (which I prefer), then a configuration file could be provided with a cron_key property, which is empty by default. The route will not work if it has not been set. The documentation should provide a way to generate a cron key, which the app developer should copy to their configuration file. Then you're set I think.

from cron.

liebig avatar liebig commented on July 24, 2024

I found some functions which help to edit files: Illuminate/Filesystem/Filesystem.php. But there is no function to edit a config value. So we have to write this ;) Laravel does the same with the application key and I like the idea that you can configure everything with commands.

When Drupal use a GET parameter, we should use it, too. A route like /cron.php?cron_key= sounds good. If the key is not set or is not right, we should return a 404.

To simplify Cron we could append the following to the start/global.php if the route and/or command job execution would be activated.

/*
|--------------------------------------------------------------------------
| Cron job definitions
|--------------------------------------------------------------------------
*/
Event::listen('cron.collectJobs', function($rundate) {
    // TODO add Cron jobs with Cron::add here
});

After that the Cron user needs only to add his jobs and configure crontab (or external service). What do you think?

from cron.

ameenross avatar ameenross commented on July 24, 2024

I found some functions which help to edit files: Illuminate/Filesystem/Filesystem.php. But there is no function to edit a config value. So we have to write this ;)

I was thinking of something more high-level. I think it's doable to create a command that produces a config file with default values and a generated cron key. Not sure if that's really worth the hassle though. The cron_key can just be empty by default (which would make the route return 404 no matter what), and the app developer instructed to do a one-off php artisan cron:keygen and copy the result to their config file (or their ENV, however they like to setup their configuration).

To simplify Cron we could append the following to the start/global.php if the route and/or command job execution would be activated.

I don't think that would be a good idea. App developers should be skilled enough to copy such code from the README and paste it where they need it.

After that the Cron user needs only to add his jobs and configure crontab (or external service).

They can already put this in their crontab:

* * * * * php /path/to/laravel/artisan cron:run

The above also has the advantage of not being limited by a webserver context (think max_execution_time). The route will additionally allow setting up remote services.

from cron.

liebig avatar liebig commented on July 24, 2024

Okay, I have to do the following:

  • add cron_key to the config file
  • create keygen command
  • adding route
  • changing the README

Did I forget anything?

from cron.

ameenross avatar ameenross commented on July 24, 2024

I guess that's about it. Of course the cron key in the default config file should be empty, and a code comment with a short explanation of the use of cron:keygen would be helpful.

from cron.

liebig avatar liebig commented on July 24, 2024

The features were added. Please test it (the route url is laravel/public/cron.php?key=YOURCONFIGKEY). I will write test cases and will change the README. I think I have to completely rewrite the README file and I want to generate PHPDoc for the API. So please be patient :)

from cron.

ameenross avatar ameenross commented on July 24, 2024

Very nice, it works! Thx for implementing! Hope you can tag a new release soon :)

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.