Comments (5)
To put it simple: right, it does not know, when it ran the last time. The solution is to not run it more often than once per minute.
This project relies on cron to be the only trigger but for dev reasons. Good thing is, cron won't trigger the command more often than once per minute, unless you really push it to do so.
If you really need to make sure, that your task is not run more often, then you will have to do so by your own means. Either inside of the task itself or by modifying the trigger script (schedule.php) for a more global approach.
from php-cron-scheduler.
@drupalista-br it's like @mark-win said, there is no way (out of the box) to know when it ran the last time, but it's true that the minimum interval for a cron job is 1 minute (in a real world scenario it won't run more than once per minute).
I can suggest you two solutions based on what you need to do:
- if you're trying to avoid the same script to overlap, you can use the
onlyOne
method. That will make sure that if the script is currently being executed by the previous cron cycle (e.g. if the script takes more that 1 minute to execute), it won't run the next minute.
$scheduler->php('script.php')->onlyOne()
- if you're trying to avoid the script to run in the same interval (also if not overlapping), you can write a simple solution by using the
then
(docs) method, keeping the last execution time (somewhere, in a db for example) and checking that on top of your script (or inside the scheduler.php file).
// Get last execution - pseudocode
$lastExecution = DB::get('last_execution')
->from('scripts_table')->where('name = script.php');
// If the last execution is more than one minute ago, then add the job to the scheduler
if ($lastExecution > '1 minute') {
$scheduler->php('script.php')->then(function () {
// After the job is executed, update the last execution time for the script
DB::update('scripts_table')
->where('name = script.php')->set('last_execution = now()');
});
}
Of course if you have any other question please feel free to reopen this issue.
from php-cron-scheduler.
Thank you guys. I am just playing around and learning. At this point I have no project requirements other than trying to understand the logic behind it.
from php-cron-scheduler.
This comes to mind, if I have a job running once daily, and it misses a day due to ... some failure or other, I would like to be able to trigger it to run at the next available interval. Is there a way to que up over-due runs?
from php-cron-scheduler.
@joshp23 not currently, I think you'll have to build external support to keep track of the jobs that did run and if that happens you should change the schedule for the jobs that didn't run. This might be easier if you store all your jobs in a database and you have an extra routine that checks for those kind of issue
from php-cron-scheduler.
Related Issues (20)
- How to do a job once? HOT 1
- CRON JOB not running automatically but run manually HOT 3
- Support PHP8.0
- how to get the number of running tasks?
- daily() and php() not working
- How does the lock file removed HOT 2
- Intelephense suggestion issue
- Fire script from a different root HOT 4
- Minute Error HOT 1
- Task start and end time
- cannot output log file HOT 1
- no way to set timezone for each job
- This library does not work for windows HOT 3
- work() cpu 100% HOT 2
- PHP 8.1 compatibility HOT 1
- Upgrade for php version 8.1 HOT 1
- Passing date will not execute the code in background
- Error when Scheduling an Object Method using ->call()
- Remove lock file of failed only-one callable job HOT 3
- Passing parameters via register_argc_argv alternative
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-cron-scheduler.