<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="scheduler-component">
      </a>
      7.5.5 Scheduler Component
     </h3>
    </div>
   </div>
  </div>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    The
    <code class="literal">
     scheduler
    </code>
    component is included in MySQL Enterprise Edition,
        a commercial product. To learn more about commercial products,
        see
    <a class="ulink" href="https://www.mysql.com/products/" target="_blank">
     https://www.mysql.com/products/
    </a>
    .
   </p>
  </div>
  <p>
   The
   <code class="literal">
    scheduler
   </code>
   component provides an
      implementation of the
   <code class="literal">
    mysql_scheduler
   </code>
   service
      that enables applications, components, or plugins to configure,
      run, and unconfigure tasks every
   <em class="replaceable">
    <code>
     N
    </code>
   </em>
   seconds. For example, the
   <code class="literal">
    audit_log
   </code>
   server
      plugin calls the
   <code class="literal">
    scheduler
   </code>
   component at its
      initialization and configures a regular, recurring flush of its
      memory cache (see
   <a class="xref" href="audit-log-logging-configuration.html#audit-log-flush-task" title="Enabling the Audit Log Flush Task">
    Enabling the Audit Log Flush Task
   </a>
   ).
  </p>
  <a class="indexterm" name="idm46045257157440">
  </a>
  <a class="indexterm" name="idm46045257156368">
  </a>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Purpose: Implements the
      <a class="link" href="server-system-variables.html#sysvar_component_scheduler.enabled">
       <code class="literal">
        component_scheduler.enabled
       </code>
      </a>
      system variable that controls whether the scheduler is
          actively executing tasks. At startup, the
      <code class="literal">
       scheduler
      </code>
      component registers the
      <code class="literal">
       performance_schema.component_scheduler_tasks
      </code>
      table, which lists the currently scheduled tasks and some
          runtime data about each one.
     </p>
    </li>
    <li class="listitem">
     <p>
      URN:
      <code class="literal">
       file://component_scheduler
      </code>
     </p>
    </li>
   </ul>
  </div>
  <p>
   For installation instructions, see
   <a class="xref" href="component-loading.html" title="7.5.1 Installing and Uninstalling Components">
    Section 7.5.1, “Installing and Uninstalling Components”
   </a>
   .
  </p>
  <p>
   The
   <code class="literal">
    scheduler
   </code>
   component implements the service
      using these elements:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      A priority queue of the registered, inactive scheduled tasks
          sorted by the next time to run (in ascending order).
     </p>
    </li>
    <li class="listitem">
     <p>
      A list of the registered, active tasks.
     </p>
    </li>
    <li class="listitem">
     <p>
      A background thread that:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         Sleeps if there are no tasks or if the top task needs more
              time to run. It wakes periodically to check whether it is
              time to end.
        </p>
       </li>
       <li class="listitem">
        <p>
         Compiles a list of the tasks that need to run, moves them
              from the inactive queue, adds them to the active queue,
              and executes each task individually.
        </p>
       </li>
       <li class="listitem">
        <p>
         After executing the task list, removes the tasks from the
              active list, adds them to the inactive list, and
              calculates the next time they need to run.
        </p>
       </li>
      </ul>
     </div>
    </li>
   </ul>
  </div>
  <p>
   When a caller invokes the
   <code class="literal">
    mysql_scheduler.create()
   </code>
   service, it creates a
      new scheduled task instance to add to the queue, which signals the
      semaphore of the background thread. A handle to the new task is
      returned to the caller. The calling code should keep this handle
      and the service reference to the scheduling service until after
      calling the
   <code class="literal">
    mysql_scheduler.destroy()
   </code>
   service.
      When the caller invokes
   <code class="literal">
    destroy()
   </code>
   and passes in
      the handle it received from
   <code class="literal">
    create()
   </code>
   , the
      service waits for the task to become inactive (if running) and
      then removes it from the inactive queue.
  </p>
  <p>
   The component service calls each application-provided callback
      (function pointer) into the same scheduler thread, one at a time
      and in ascending order, based on the time each requires to run.
  </p>
  <p>
   Developers who wish to incorporate scheduler-queueing capabilities
      into an application, component, or plugin should consult the
   <code class="filename">
    mysql_scheduler.h
   </code>
   file in a MySQL source
      distribution.
  </p>
 </div>
 <br/>
</div>
