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:48] – [Job capacity] 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 | + | ==== Running daily (at a specific time) ==== |
+ | |||
+ | This will schedule the job to run daily at the given date and time. | ||
+ | |||
+ | <code php> | ||
+ | $job = Job::getJob(' | ||
+ | $job-> | ||
+ | $job-> | ||
+ | </ | ||
+ | |||
+ | ==== Running always (daemon job) ==== | ||
+ | |||
+ | This will start the given job if it isn't already | ||
+ | |||
+ | <code php> | ||
+ | $job = Job:: | ||
+ | $job-> | ||
+ | </ | ||
+ | |||
+ | ===== Running | ||
+ | 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 ===== | ||
Line 34: | 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 50: | Line 76: | ||
If a job doesn' | If a job doesn' | ||
+ | ===== Errors in job ===== | ||
+ | |||
+ | Job is expected to produce no output if everything goes well and provide error output if something goes wrong, as the output from the job is collected as an error message. | ||
+ | |||
+ | If an error occurs the '' | ||
+ | |||
+ | ===== Job statistics ===== | ||
+ | Some job statistics is gathered on the job objects as properties. | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== 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.1571651304.txt.gz · Last modified: 2019/10/21 09:48 by sahl