crunzphp / crunz Goto Github PK
View Code? Open in Web Editor NEWA PHP-based job scheduler
License: MIT License
A PHP-based job scheduler
License: MIT License
Might want to notate that closures don't run in parallel (at least on windows). php binaries/other commands do.
Description
As discussed in #14 passing non-list array in second parameters breaks ProcessUtil
and is not supported by new versions of symfony/process
.
Example
Non-list param:
<?php
use Crunz\Schedule;
$schedule = new Schedule();
$paramsTest = $schedule->run(
PHP_BINARY,
[
'-v',
'--ini' => false,
]
);
List of strings in param:
<?php
use Crunz\Schedule;
$schedule = new Schedule();
$paramsTest = $schedule->run(
PHP_BINARY,
[
'-v',
'--ini',
'0',
]
);
If you have a ...Task.php
file that throws an exception, none of the jobs run.
Ive been stung by this in past and without being able to call the task pragmatically (or atleast I cant work out how) you have to-do extra work to make sure this isn't preventing your jobs from being run.
Could try to submit a PR but would need some pointers ๐
I'm trying to achieve something like what wordpress is doing, just running cronjobs cronless. I tried doing it with with exec, but they don't seem to be executing, and might be something wrong with my setup, not sure yet. I would like to know whats the state of crunz on this before i dig deeper.
Description
An option to indicate that the task should run on only one server, similar to laravel's onOneServer like described in https://laravel.com/docs/9.x/scheduling#running-tasks-on-one-server
It is not possible to achieve the same results with preventOverlapping
because the current implementation of preventOverlapping
allows passing only locks implementing BlockingStoreInterface. It leads task execution once per server, but not in the same time.
Currently there is no wat to add an additional "Error" callback in the same way as we can with ->before() and ->after().
Can the "addErrorCallback()" method be changed from private
to public
.
Description
lavary/crunz#152
I am moving this over from lavary/crunz
because it's still a needed feature for this lib.
Description
The documentation indicates that RetryTillSaveStore
from Symfony should be used to prevent overlapping executions. However, that class was deprecated in 5.2 and, as of 6.0, it no longer exists.
The functionality has been moved into Lock
.
Update documentation accordingly.
OS: windows 10
PHP: 7.4
"lavary/crunz": "^3.2"
vs "crunzphp/crunz": "^3.3"
$task->everyTwoMinutes();
or $task->cron('*/2 * * * *');
what i'm doing is running ./vendor/bin/crunz schedule:run
repeatly
lavary : run as expected No event is due!
crunzphp: always run / execute task. No difference behaviour between everyMinute vs everyTwoMinutes
i'm also confirm that this bug is not happend for $task->everyThreeMinutes()
or $task->cron('*/3 * * * *');
Crunz version: 3.7.0
PHP version: 8.2
Operating system type and version: AlmaLinux v8.9.0
Description
After upgrading Crunz to the latest version, contents of my task (everything enclosed in $scheduler->run(function () {
) were no longer triggered.
The file itself was triggered, which could be verified by placing a debug statement in the file somewhere, e.g. right after the $scheduler = new Schedule();
line
How to reproduce
$scheduler = new Schedule();
// E.g. sending a mail here does work
$task = $scheduler->run(function () {
// Any code here does not get triggered
});
$task
->description('Example description')
->preventOverlapping()
->everyMinute();
return $scheduler;
Crunz version: 3.3.2
PHP version: 7.4.29/8.1.6
Operating system type and version:
CENTOS/MacOS Monterey
Description
using sendOutputTo command is not writing task output to file
How to reproduce
Simple task:
<?php
use Crunz\Schedule;
$schedule = new Schedule();
$taskToSchedule = $schedule->run(function () {
echo 'Testing... 1, 2, 3', PHP_EOL;
});
$taskToSchedule->everyMinute();
$taskToSchedule->description('Description')
->sendOutputTo('/home/pinkele/public_html/testoutput.txt');
return $schedule;
I expect the output to be in the designated file, but it's not. This result is the same using CENTOS/PHP7.4.x or locally on my Mac using Monterey and either PHP7.4.x or 8.1.x
Possible Solution
Additional context
Cron job is configured to email me any output. I receive no emails, but if I remove the call to sendOutputTo, it behaves as expected and emails me the output of the task.
Description
Its cool that you can run vendor/bin/crunz s:l
but it would be really good if we could see these jobs displayed on a web interface.
Unfortunately I'm not quite sure how to approach this issue so im requesting it but cant produce a PR (which I know is rude sorry).
Happy to give it a shot but will need some pointers ๐
Description
It might be interesting to be able to have the log in a different format than those possible at the moment.
It might be interesting to have it in JSON format so as to be able to use it as input data for further batches or for a more immediate reading of the return data.
Example
It could be something like this:
{
"execution_date_time" : "2023-09-27 10:38:00",
"duration_seconds" : "60",
"outcome" : "true",
"output" : ".......",
"error" : "......."
}
I am available to help you if you are interested.
Hi
Description
Sometimes you need to pause a task, and it would be nice if you could set a status for tasks.
And so on, it would be good to think
Also display the "Status" column in the schedule:list table
Example
use Crunz\Schedule;
$scheduler = new Schedule();
$task = $scheduler->run('command/to/execute');
$task
->description('Task description')
->in('path/to/your/command')
->preventOverlapping()
->everyThirtyMinutes()
->weekdays()
->setStatusPause() // Set status
;
return $scheduler;
Description
Is there a possibility of logging the errors and output files name in date format?
Description
Due to release of Symfony 7, support of this version will be more than appreciated :)
Crunz version: x.y.z
3.2.2
PHP version: x.y.z
8.1
Operating system type and version:
Ubuntu 22.04 LTS
Description
ProcessUtils::escapeArgument() is throwing a fatal error in PHP 8.1:
PHP Fatal error: Uncaught TypeError: str_replace(): Argument #3 ($subject) must be of type array|string, bool given in vendor/crunzphp/crunz/src/ProcessUtils.php:84
Crunz version: 2.3.1
PHP version: 7.4.29
Operating system type and version:
MacOS Monterey (also to be deployed on RH)
Description
Composer installing older version of crunz. From CLI, I use composer require crunzphp/crunz
and it installs v 2.3.1, which is marked EOL on the repo.
How to reproduce
from CLI, do composer require crunzphp/crunz
Possible Solution
I could go into composer.json and change version by hand, but shouldn't that happen automatically?
Additional context
I am using the latest version of composer. Not sure if the installed version might be dependent on what else I might have installed.
Description
Currently we can run individual task only using dynamic numeric id
-t, --task=TASK Which task to run. Provide task number from schedule:list command.
Which does not guarantee that it does the same task every time.
What do you think for introduce non-numeric identifier which can be used alongside with numeric id for run command in more predictable way?
Example
<?php
use Crunz\Schedule;
$schedule = new Schedule();
$task = $schedule->run(PHP_BINARY . ' backup.php', ['--destination' => 'path/to/destination']);
$task
->identifier('backup')
->description('Copying the project directory');
return $schedule;
Usage:
Run
schedule:run --task=backup
List
crunz schedule:list
+---+------------+-----------------------+-------------+----------------+
| # | Identifier | Task | Expression | Command to Run |
+---+------------+-----------------------+-------------+----------------+
| 1 | backup | Task description | 0 * * * 1 * | scripts.php |
+---+------------+-----------------------+-------------+----------------+
We have an error when using crunz with different projects on a same computer. The cache directory is computed in src/Application::getBaseCacheDir() using the function \sys_get_temp_dir().
So for all our projects, the cache is the same, but we need to have a different cache directory. (In our case we have some error)
A possible solution is to create an option in the configuration file and use it in the function src/Application::getBaseCacheDir().
I been trying to run task in serialize manner. Meaning after the first task is done should run another schedule task. Is this possible? Using the after function seems to fail with error Call to a member function isRunning() on null
The second command depends on the result processed from the first command.
Crunz version: 3.4.1
PHP version: 8.2.8
Description
The timezone setting in crunz.yml is ignored for task life time checks in https://github.com/crunzphp/crunz/blob/v3.4.1/src/Event.php#L1191-L1213 . This causes tasks to run outside of specified time ranges.
How to reproduce
Have date.timezone=UTC
in your php.ini and timezone: Europe/Berlin
in your crunz.yml
crunz task:
<?php
use Crunz\Schedule;
$scheduler = new Schedule();
$scheduler
->run('echo "Hello World!"')
->everyMinute()
->between('12:00', '20:00');
return $scheduler;
play around with values for between and observe that it is following UTC times and not Europe/Berlin as configured.
Description
I want to know which file a particular scheduled event is defined in. This information is not currently exposed in either the table or JSON output format.
In my use-case I want to have this information in the JSON format so it can be machine-parsed.
Example
The table and JSON output of schedule:list
should show the filename of the event/schedule.
Note
It is my intention to submit a PR for this feature.
First, thanks for this awesome library. I am using it for learning purposes. I have a few tasks in my tasks directory, all of which are php files running with the PHP BINARY by Crunz. I was wondering if there is a way to delete the php file after its execution.
Things that I have tried to achieve this:-
UNLINK(__FILE__);
to the task php. But, I can't have it before return $schedule
as the script won't complete and the task file gets deleted. I can't have it afterwards either, as anything after return $schedule
doesn't run.$schedule->run(PHP_BINARY . -r 'UNLINK(__FILE__');
But, __FILE__
here returns a value of Command line code
and I tried various versions of it, but none of them work.I am trying to self destroy the task once it has been executed from within the task php file itself. I am aware of using sh or bash to do this. But, I would really love to know if there was a way to achieve this from within the PHP file itself.
I want to set the log files in the config relative to the project in the logs folder.
crunz.yml
log_errors: true
errors_log_file:logs/error.log
log_output: true
output_log_file: logs/output.log
Project Folder Structure
We can mimic this now, but it would be great if it were built in.
Description
Technically jobs can only run every minute.
But it is possible to allow them to run, for example, every 30 seconds if you were to automatically schedule two jobs every minute, with one of them having a 30 second delay before executing.
So Job 1 runs immediately, Job 2 starts a 30 second timer, then runs.
Bam, we're cooking at twice a speed ๐ฅ
To do more frequent runs is similar, just needing to kick off as many jobs as needed with the requisite delays (or kick off one job that runs for the full minute and kicks off the jobs at the correct time - if doing this, technically any options are available for when to run).
Example
$task = $schedule->run(PHP_BINARY . ' email.php');
$task->every[One|Two|Three|Four|Five|Six|Ten|Twelve|Fifteen|Twenty|Thirty]Seconds();
I think the best option is to allow any integer divisor of 60, so: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30.
It could be that those shorter periods are too much - but a developer can decide that for themselves depending on what they're trying to accomplish.
Could also be something like:
$task = $schedule->run(PHP_BINARY . ' email.php');
$task
->second([5, 10, 15, 20, 30])
->minute(['1-30', 45, 55])
->hour('1-5', 7, 8)
->dayOfMonth(12, 15)
->month(1);
This form may be confusing though if someone tries an invalid option for second.
Description
It would be very helpful to have a possibility to return multiple different Schedule
objects from one task-file.
One possible usage scenario is external schedule source for Schedules.
Possible implementations are simple array or a Schedule-collection object.
Example
use Crunz\Schedule;
//...
$schedules = []; // new ScheduleArrayObject();
forearch ($externalDefinitions as $definition) {
$schedule = new Schedule();
// configure $schedule
// ...
$schedules[] = $schedule;
}
return $schedules;
In the Event.php class there are some public variables of the class and some public methods such as getExpression(), getId() which are very useful if you integrate the class and want to have details on the task you want to analyze.
Unfortunately there is no way to determine if the task has a lifetime configured by "from", "to" or "between" method.
Could be useful to have some getters for "from" and "to" configurations or have public variables to read that.
Theoretically the change could be quite simple.
You can add the variable "from" and "to" to the top of Event.php file with something like that:
/**
* Lifetime from.
*
* @var \DateTime|string
*/
public $from;
/**
* Lifetime to.
*
* @var \DateTime|string
*/
public $to;
and then modify class method from and to at line 448 and 460 with something like that:
/**
* Check if event should be on.
*
* @param string $datetime
*
* @return self
*/
public function from($datetime)
{
$this->from = $datetime;
return $this->skip(fn () => $this->notYet($datetime));
}
/**
* Check if event should be off.
*
* @param string $datetime
*
* @return self
*/
public function to($datetime)
{
$this->to = $datetime;
return $this->skip(fn () => $this->past($datetime));
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.