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…

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…

Build Web Site for Hosting Provider (HTML Provided)

Require someone with strong skills in Concrete 5 CMS (www.concrete5.org). Please be ready to provide examples. Build a Web hosting website using existing HTML provided; you will have to insert the HTML/CSS of pages provided into Concrete 5. You may h…

Screwed up... need to rename the "jobs" folder.

Hey all, I pulled a stupid move awhile ago and need some advice on correcting it with a more permanent solution. I in my infinite wisdom removed the "empty" jobs folder from the site and told publications that they could market job openings using http…

Call a controller method from a Job?

Hi is it possible to call a Controller method from a Job? As it's a job, the required controller isn't loaded I guess, so I think I'll need to create a controller object and then I should be able to call the method inside it. Any tips to get me …