# Module HowTo - Jobs

Jobs can be used to run actions in regular intervals like daily.
They are configured on tab "Jobs" in LAM server profile.
See ppolicyUser module for an example.

## Adding the job class

The module defines the list of supported jobs with function getSupportedJobs().

/** * Returns a list of jobs that can be run. * * @param LAMConfig $config configuration * @return array list of jobs */ public function getSupportedJobs(&$config) { return array( new PPolicyPasswordNotifyJob() ); }

The job class itself can be in the module file or in any file included by the module file. Please add the class definition in an interface check as the example below. The job interface is not loaded on all pages.

if (interface_exists('\LAM\JOB\Job')) { /** * Job to notify users about password expiration. * * @package jobs */ class PPolicyPasswordNotifyJob implements \LAM\JOB\Job { [...] }

## Basic job attributes

Each job needs to provide a unique name, icon, alias and job description. You need also to specify if multiple configurations of the same job are allowed on a server profile.
If your job requires any configuration options then use get/checkConfigOptions() functions.

## Database

Jobs can access a database to read and store data about job runs. Use this e.g. if you need to save any status information across job runs.
Database access is specified with needsDatabaseAccess().
There is a built-in database upgrade mechanism. Your job must return its current schema version with getDatabaseSchemaVersion() and LAM will call updateSchemaVersion() whenever it detects a higher version in job class than on database.

## Execution

When jobs are run the the execute() function is called. Please put all your logic in there.

##