peppeocchi / php-cron-scheduler

PHP cron job scheduler
MIT License
811 stars 144 forks source link

One job for many executionTime definition (AND) #43

Open mrcnpdlk opened 6 years ago

mrcnpdlk commented 6 years ago

Hi, is any way to use AND for simple expression (against using when() method) while defining execution time for one Job? For example (pseudo code):

    $scheduler
        ->php(`some php script`)
        ->at('1 10 * * 1,2,3')
        ->at('1 8 * * 4,5')
peppeocchi commented 6 years ago

@mrcnpdlk unfortunately this is not currently supported, but it would be a nice feature to add. Anyway you can schedule your script as many times as you want in the same file, in this case it's highly recommended to set a different identifier for each job, because the identifier if not defined will be generated from the command name, and the identifier is used for a few things during the lifecycle of each job (scheduling the same job without identifier will cause the identifier to be the same for both jobs, and it could lead to unexpected behaviours).

For example you could do something like this

$scheduler->php('some php script', null, [], 'myCustomId')
    ->at('1 10 * * 1,2,3');

$scheduler->php('some php script', null, [], 'myOtherCustomId')
    ->at('1 8 * * 4,5');

I'll leave this issue open for now, if there is more demand about your suggestion I'll work on adding it to a future release.

Thank you!