<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
   <title>Posts by Mark Carey on Learning Movable Type</title>
   <link rel="alternate" type="text/html" href="http://www.learningmovabletype.com/" />
   <link rel="self" type="application/atom+xml" href="http://www.learningmovabletype.com/contributors/markcarey/" />
   <id>tag:,2008-02-25:/5</id>
   <updated>2007-12-14T12:36:06Z</updated>
   <subtitle>Tutorials and helpful tips for the Movable Type web publishing system</subtitle>
   <generator uri="http://www.movabletype.org/">Movable Type Publishing Platform 4.01</generator>

<entry>
   <title>Movable Type Scheduled Tasks</title>
   <link rel="alternate" type="text/html" href="http://www.learningmovabletype.com/a/movable_type_scheduled_tasks/" />
   <id>tag:www.learningmovabletype.com,2007://5.1982</id>
   
   <published>2007-12-12T20:53:56Z</published>
   <updated>2007-12-14T12:36:06Z</updated>
   
   <summary>Movable Type has a scheduled tasks system that is used to perform certain tasks on scheduled basis. Built-in tasks include expiring junk (spam) trackbacks and comments, and posting entries that were scheduled to to published at a certain date / time. Movable Type plugins can also use scheduled tasks, as...</summary>
   <author>
      <name>Mark Carey</name>
      <uri>http://mt-hack.com</uri>
   </author>
   
      <category term="Exploring MT" scheme="http://www.sixapart.com/ns/types#category" />
   
      <category term="Plugins" scheme="http://www.sixapart.com/ns/types#category" />
   
   <category term="administration" label="Administration" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="schedulingposts" label="Scheduling Posts" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="en" xml:base="http://www.learningmovabletype.com/">
      <![CDATA[<p>Movable Type has a <em>scheduled tasks</em> system that is used to perform certain tasks on scheduled basis.  Built-in tasks include expiring junk (spam) trackbacks and comments, and posting entries that were scheduled to to published at a certain date / time.  Movable Type plugins can also use scheduled tasks, as some of my plugins do (including <a href="http://mt-hacks.com/visitorstats.html">Visitor Stats Pro</a>, <a href="http://mt-hacks.com/ajaxrating.html">Ajax Rating Pro</a>, and <a href="http://mt-hacks.com/blogjanitor.html">Blog Janitor</a>).  One of the benefit of scheduled tasks is to improvement performance and user experience -- resource intensive functions can be run without making admins, authors, and commenters wait while they complete.</p>

<p><strong>Triggering Scheduled Tasks</strong></p>

<p>Scheduled task will only run when they are <em>triggered</em>.  This is important.  Even if a task is scheduled to run every hour, it scheduled tasks don't get triggered, <em>the task will never run</em>.  By default Movable Type will trigger scheduled tasks in the following cases:</p>

<ol><li>You receive a junk (spam) comment or trackback. <strong>Note: this will <em>only</em> trigger the 'Junk expiration' task - it won't trigger plugin tasks.</strong></li>
<li>You view or download an XML "activity feed" (These feeds show up on with orange feed links on many screens of the admin MT interface, including entry and comment listings, and activity log).</li>
<li>When the <em>run-periodic-tasks</em> script (found in the 'tools' directory of MT) is run via the command line or via cron.</li></ol>]]>
      <![CDATA[<p><strong>Testing Scheduled Tasks</strong></p>

<p>Here is an easily method that I use to test scheduled tasks and make sure they are running correctly:</p>

<ol><li>Go to System Overview > Activity Log.</li>
<li>Click the "Activity Feed" link on the right side of the page.</li>
<li>After the XML feed displays, hit the back button.</li>
<li>Now refresh the System Activity Log.</li>
<li>Read the recent log entries.  If tasks were just triggered, there should be a message stating that tasks were run, along with the names of those tasks.  In addition, some plugin tasks may post custom log messages to the Activity Log, providing more information about the task completed.</li></ol>

<p>Note that in some cases, depending of the task, you may have to rebuild your pages after the task has run, in order to see the results of the task. One example of such a case is my Visitor Stats Pro plugin, in which a scheduled task tallies the page views of each entry, so that they can be displayed in a "Most Read Entries" widget that lists the most popular entries.</p>

<p><strong>Setting Up a Cron Job</strong></p>

<p>To ensure that scheduled tasks get triggered on a regular basis, I recommend setting up a cron job to run the run-periodic-tasks script once per hour. If you are not familiar with setting up cron jobs, please read the following helpful article: <a href="http://www.learningmovabletype.com/a/000757scheduled_posts/">Scheduled Postings and Cron Jobs</a>.</p>]]>
   </content>
</entry>

</feed>

