User Tools

Site Tools


job_class

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
job_class [2021/02/11 12:59] – Concept of server job sahljob_class [2023/06/27 07:30] (current) sahl
Line 8: Line 8:
 ===== Scheduling a job ===== ===== Scheduling a job =====
  
-A job is basically a function in a class and can be scheduled like this:+A job is basically a reference to a function in a class that will be called at given times. This can be initiated in a few different ways: 
 + 
 +==== Running at a specific interval ==== 
 + 
 +A job can run in a specific interval. For example the following code will ensure that the function ''User::checkExpireDate()'' will be called once each hour.
  
 <code php> <code php>
Line 15: Line 19:
 </code> </code>
  
-This will ensure that the function ''User::checkExpireDate()'' will be called once each hour.+==== Running once (at a specific time====
  
-Another way to schedule job, could be:+This will schedule the job to run exactly once at the given date and time.
  
 <code php> <code php>
 $job = Job::getJob('User', 'sendEmailNotice', Job::FREQUENCY_ONCE); $job = Job::getJob('User', 'sendEmailNotice', Job::FREQUENCY_ONCE);
-$job->next_start = new Timestamp('2019-12-31 23:59:00');+$job->next_start = new Time('2019-12-31 23:59:00');
 $job->save(); $job->save();
 </code> </code>
  
-This will schedule the job to run once at the given date and time.+If //next_start// is omitted, the job will run as soon as possible.
  
-The key to given job is the class and the function (and the instance it is running from)So when you use ''getJob'' you will get an existing job if such a job exists or a new job if no existing job existed.+==== Running daily (at specific time) ==== 
 + 
 +This will schedule the job to run daily at the given date and time. 
 + 
 +<code php> 
 +$job = Job::getJob('Team''AdvertiseWork', Job::FREQUENCY_SETTIME); 
 +$job->next_start = new Time('2019-12-31 20:00:00'); 
 +$job->save(); 
 +</code> 
 + 
 +==== Running always (daemon job) ==== 
 + 
 +This will start the given job if it isn't already running. If the job exits, it will be started again ASAP. 
 + 
 +<code php> 
 +$job = Job::getJob('Chat', 'NetworkDaemon', Job::FREQUENCY_ALWAYS); 
 +$job->save(); 
 +</code>
  
 ===== Running a job ===== ===== Running a job =====
job_class.1613048358.txt.gz · Last modified: 2021/02/11 12:59 by sahl

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki