Jobs

Accessible through the system section of the dashboard, jobs are ways of automating certain processes available to concrete5. These jobs can be run from the dashboard, or easily cronned and run from the server at specified intervals.

Examples of Jobs

concrete5 ships with three jobs: Reindex Search Engine, Generate sitemap.xml and Run Mail Importers. Each of these tasks is suited for a job, in that they need to be run periodically, require no user input and may take a little bit of time to run.

Creating Your Own Job

Creating your own job is as simple as creating a new class in the Job format, and adding it to the jobs/ directory in your local web root. This job will then appear on the Jobs page in your site's dashboard, can then be installed and run easily.

Step 1. Create the File

In your local jobs/ directory, create a file in the typical concrete5 handle format. (all lowercase, with underscores separating spaces. e.g. "index_search.php" or "clear_cache_files.php")

Create a class in this file

Within this file, take the name of your file (minus .php) and camelcase it, and use that as your job’s class name, while extending the Job class.

	class ClearCacheFiles extends Job

Specify the Job name and description

Within this file, define the method getJobName() and getJobDescription(), with each returning the relevant piece of information about the job.

Define the run() function

Inside a run() function of your Job, define whatever programming logic you wish to execute when the Job is run.

Setup error handling and output

Within your run() method, handle errors by using the throw() method and native PHP exception support. Any exceptions that occur within your job will cease the job from running and be reported to the administrator when they next visit the Jobs page in the dashboard.

If you would like to return custom output for the status of your job, simply return a string from your run() method.

Installing a Job with a Package

As of concrete 5.4, addon developers may install Jobs with their packages. To do this, simply include the job file in a jobs/ directory within the package, and execute the following code from within your package's install() command:

	Loader::model("job");
	Job::installByPackage("your_job_handle", $pkg);

Any jobs installed in this way will automatically be removed if your package is uninstalled.

Recent Discussions on this Topic

Programmatically creating pages and specifying content

Ok...this is a biggie! Possibly my largest, and definitely my most complex, Concrete5 project to date is looming on the horizon, and I would really love to get a couple of things straight (even if just from a high 'yes, this is possible' type level) befor…

Seeking Freelance Work

Hello I am now available for freelance work. I have skills in PHP, MySQL, HTML, CSS, Jquery, javascript, database design, responsive web design and graphic design and many more. I specialize in custom website, theme and add-on development for Concrete. …

Include Jobs/Single Pages in Package Upgrade

I have recently added some new single pages and jobs to a package that I have built. These pages install fine on a fresh install of the package, but I am not sure how to get them to be included in an upgrade. I suppose I could add the appropriate code t…

What about jobs directory in concrete5?

In the directory structure, they don't mention about jobs directory. What work it actually do? for what purpose we can use this directory? could anyone explain about this...? Thanks in advance....

Automatically check date daily

Hi, I have a single page in my site. I want to check and get the current date by using my single page to do some process depends upon this. So, I should automatically run this single page daily. There is any suggestions to do this task using concret…