job_class
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
job_class [2019/10/21 09:59] – [Scheduling a job] sahl | job_class [2023/06/27 07:30] (current) – sahl | ||
---|---|---|---|
Line 3: | Line 3: | ||
The Job class is a structure for scheduling and performing background jobs in Platform. In order for the Job class to work, one must set up a cronjob running ''/ | The Job class is a structure for scheduling and performing background jobs in Platform. In order for the Job class to work, one must set up a cronjob running ''/ | ||
The Job class depends on running in a Linux environment with commands such as //ps// and //kill// being available. | The Job class depends on running in a Linux environment with commands such as //ps// and //kill// being available. | ||
+ | |||
+ | Jobs are usually running in the context of an instance, but it is also possible to have serverjobs, which isn't related to a specific instance. See later. | ||
===== 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 |
+ | |||
+ | ==== Running at a specific interval ==== | ||
+ | |||
+ | A job can run in a specific interval. For example the following code will ensure that the function '' | ||
<code php> | <code php> | ||
Line 13: | Line 19: | ||
</ | </ | ||
- | This will ensure that the function '' | + | ==== Running once (at a specific time) ==== |
- | Another way to schedule | + | This will schedule |
<code php> | <code php> | ||
$job = Job:: | $job = Job:: | ||
- | $job-> | + | $job-> |
$job-> | $job-> | ||
</ | </ | ||
- | This will schedule | + | If // |
- | The key to a given job is the class and the function (and the instance it is running from). So when you use '' | + | ==== Running daily (at a specific time) ==== |
- | ===== Running a job ===== | + | This will schedule the job to run daily at the given date and time. |
+ | <code php> | ||
+ | $job = Job:: | ||
+ | $job-> | ||
+ | $job-> | ||
+ | </ | ||
+ | |||
+ | ==== 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:: | ||
+ | $job-> | ||
+ | </ | ||
+ | |||
+ | ===== Running a job ===== | ||
The job will be executed by calling the provided function in the provided class, with the job itself as a parameter. The correct instance is already activated, but please be aware that the job is provided in read mode, so we don't block the job if the execution of the function takes a long time. | The job will be executed by calling the provided function in the provided class, with the job itself as a parameter. The correct instance is already activated, but please be aware that the job is provided in read mode, so we don't block the job if the execution of the function takes a long time. | ||
+ | |||
===== Timing ===== | ===== Timing ===== | ||
The '' | The '' | ||
Line 37: | Line 60: | ||
'' | '' | ||
- | '' | + | '' |
'' | '' | ||
===== Modifying the job on the fly ===== | ===== Modifying the job on the fly ===== | ||
- | The function which is called from a job, will always be passed the job as the first parameter. This can be used to reschedule the job or totally delete the job. | + | The job function, will always be passed the job as the first parameter. This can be used to reschedule the job or totally delete the job. |
===== Limiting run time ===== | ===== Limiting run time ===== | ||
Line 69: | Line 92: | ||
'' | '' | ||
+ | |||
+ | ===== Server jobs ===== | ||
+ | |||
+ | As mentioned earlier jobs run in relation to instances. It is also possible to have a server job, which is a job that doesn' | ||
+ | |||
+ | <code php> | ||
+ | $server_job = Job:: | ||
+ | $server_job-> | ||
+ | </ | ||
+ |
job_class.1571651986.txt.gz · Last modified: 2019/10/21 09:59 by sahl