---
schema_version: "1"
id: 66d7b51bf99ad17f4bf4b4d319f8b7b3e59fa425a5eb40fa3aec4e50bfaa4575
title: Scheduler エンドポイント (トリガー)
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/mule-runtime/4.5/scheduler-concept.md
canonical_url: https://docs.mulesoft.com/jp/mule-runtime/4.5/scheduler-concept
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 2e88fddf562819d58c465d6c08780bc9df475a712a94fb4d62576d53eb068e73
description: MuleSoft Documentation Site
release: "4.5"
latest: false
---
# Scheduler エンドポイント (トリガー)

Scheduler コンポーネントは、時間ベースの条件に基づいてフローの実行をトリガーする Mule イベントソースです。たとえば Scheduler によって、5 秒ごと、または指定したタイムゾーンで毎日 12 時 00 分にフロー処理をトリガーするメッセージを作成して送信される場合があります。

Mule アプリケーションに Scheduler を追加するときは次の点を考慮してください。

- Scheduler は、Mule が動作しているマシンと同じタイムゾーンを使用します。ただし、アプリケーションが CloudHub で動作している場合は、アプリケーションが動作している地理的リージョンに関係なく、Scheduler は UTC タイムゾーンに準拠します。
    
    Scheduler 用に別のタイムゾーンを設定する場合は、​[Cron (​`<cron/>`​)](#props_cron_expressions)​の​`「timeZone」`​を参照してください。
- `disallowConcurrentExecution`​ プロパティを使用すると、以前にトリガーされた実行の処理中に Scheduler でフローの実行がトリガーできないようにできます。
- スケジュールされたトリガー時に利用できるリソースが 1 つもないために ​[back-pressure](https://docs.mulesoft.com/jp/mule-runtime/4.5/execution-engine#backpressure)​ が発生した場合、その実行はスキップされます。
- Mule Runtime Engine クラスターやマルチワーカー CloudHub デプロイメントでは、Scheduler はプライマリノードのみで (つまり 1 つの Mule インスタンスのみで) 実行されます。

## [](#アーキテクチャ)アーキテクチャ

他の Mule イベントソースコンポーネントと同様、Scheduler は Mule フローの最初のコンポーネントです。

![Mule フローの Scheduler コンポーネント](/mulesoft/current/ja-jp/mule-runtime/4.5/_images/scheduler-component-ex.png)

Scheduler の XML は以下の要素で構成されます。

- `<scheduler />`​: Scheduler の最上位レベルの要素。
- `<scheduling-strategy />`​: 次のいずれかの子を受け入れる第 2 レベル要素。
    
    - `<fixed-frequency />`​: 毎秒などの一般的なスケジュール頻度向け。
    - `<cron />`​: [Cron 式](#cron_expressions)​およびタイムゾーン設定向け。

Scheduler により、固定の頻度、または Cron 式に基づいた間隔でスケジュール戦略が設定されます。次に例を示します。

- 次の Scheduler の固定の頻度設定では、15 秒ごとに実行されます。
    
    ```xml
    <flow name="ex-fixed-frequency-flow" >
      <scheduler doc:name="Scheduler">
        <scheduling-strategy>
          <fixed-frequency frequency="15" timeUnit="SECONDS" />
        </scheduling-strategy>
      </scheduler>
      <!-- One or more processors here. -->
    </flow>
    ```
- Scheduler の Cron 式によって 15 秒ごとにフローが新たに実行され、Mule メッセージの生成がトリガーされます。
    
    ```xml
    <flow name="ex-cron-expression-flow" >
      <scheduler doc:name="Scheduler" >
        <scheduling-strategy >
          <cron expression='0/15 * * * * ? '/>
        </scheduling-strategy>
      </scheduler>
      <!-- One or more processors here. -->
    </flow>
    ```

1 つ以上のプロセッサーが Scheduler に従う必要があります。プロセッサーには、HTTP Request 操作や Transform Message コンポーネントなど、Mule コンポーネントやコネクタ操作が含まれます。プロセッサーを提供しない場合、​`MuleRuntimeException`​ が発生し、Mule アプリケーションのデプロイメントが失敗して、次の ERROR メッセージがログに記録されます (読みやすいように編集済み)。

```logs
ERROR ...MuleRuntimeException ...
The content of element 'flow' is not complete.
One of '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor,
"http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor}'
is expected.
```

Scheduler 属性については、​[参照](#reference)​を参照してください。

## [](#reference)参照

Scheduler 要素は実行間隔および同時実行を設定するための属性を受け入れます。

### [](#props_scheduler)Scheduler (​`<scheduler/>`​)

デフォルトでは、Scheduler は設定されたケイデンスでフローの別のインスタンスを実行する前にそのフローの前の実行が完了するまで待機しません。この動作は、設定 XML で ​`disallowConcurrentExecution="true"`​ 属性を設定することで変更できます。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 20%;">
<col style="width: 80%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">属性 XML</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>disallowConcurrentExecution</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>この属性を ​<code>true</code>​ に設定すると、Scheduler は前の実行がまだ処理中であればスケジュールされた実行をスキップします。フローが完了すると、Scheduler は次に設定された間隔で実行されます。デフォルト値は ​<code>false</code>​ です。</p>
</div></div></td>
</tr>
</tbody>
</table>

次の例では、Scheduler はフローが完了までに要する時間が固定の頻度である 10 ミリ秒を超えると実行をスキップします。

```xml
<flow name="scheduler-disallowConcurrentExecution-ex" >
  <scheduler doc:name="Scheduler" disallowConcurrentExecution="true" >
    <scheduling-strategy>
      <fixed-frequency frequency="10" timeUnit="MILLISECONDS"/>
    </scheduling-strategy>
  </scheduler>
  <!-- processors here -->
</flow>
```

Scheduler が実行をスキップするたびに、たとえば次のような ​`Execution skipped`​ メッセージがログに記録されます (読みやすいように編集済み)。

```logs
INFO  2022-11-09 15:15:43,082 ...
...scheduler.DefaultSchedulerMessageSource:
Flow 'scheduler-disallowConcurrentExecution-ex' is already running and
'disallowConcurrentExecution' is set to 'true'. Execution skipped.

INFO  2022-11-09 15:15:43,083 ...
...scheduler.DefaultSchedulerMessageSource:
Flow 'scheduler-disallowConcurrentExecution-ex' is already running and
'disallowConcurrentExecution' is set to 'true'. Execution skipped.
```

### [](#props_fixed_frequency)固定頻度 (​`<fixed-frequency/>`​)

固定頻度のスケジュール戦略では、次の属性を受け入れます。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 14.2857%;">
<col style="width: 14.2857%;">
<col style="width: 14.2857%;">
<col style="width: 57.1429%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">属性</th>
<th class="tableblock halign-left valign-top">XML</th>
<th class="tableblock halign-left valign-top">Default (デフォルト)</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><strong>Frequency (頻度)</strong></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>frequency</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>1000</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>指定された ​<code>timeUnit</code>​ 設定で Scheduler がフローをトリガーする頻度。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><strong>Start Delay (開始遅延)</strong></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>startDelay</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>0</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>アプリケーションが起動した後で Scheduler の最初の実行を遅延する時間。このプロパティでは頻度と同じ ​<code>timeUnit</code>​ を使用します。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><strong>Time Unit (時間単位)</strong></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>timeUnit</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>MILLISECONDS</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>frequency</code>​ と ​<code>startDelay</code>​ の値の次のいずれかの時間単位。</p>
</div>
<div class="paragraph">
<p><code>MILLISECONDS (ミリ秒)</code>​、​<code>SECONDS (秒)</code>​、​<code>MINUTES (分)</code>​、​<code>HOURS (時)</code>​、または ​<code>DAYS (日)</code>​</p>
</div></div></td>
</tr>
</tbody>
</table>

次の戦略では、最初の 10 秒の遅延後、10 秒ごとに Scheduler の実行を遅延します。

```xml
<scheduler doc:name="Scheduler" >
  <scheduling-strategy >
    <fixed-frequency frequency="10" timeUnit="SECONDS" startDelay="10"/>
  </scheduling-strategy>
</scheduler>
```

### [](#props_cron_expressions)Cron (​`<cron/>`​)

Cron 式を使用することで、より複雑なスケジューリング戦略を設定できます。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 66.6668%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">属性</th>
<th class="tableblock halign-left valign-top">XML</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><strong>Expression (式)</strong></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>expression</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Scheduler をトリガーする Cron 式。デフォルトの Cron 式はありません。式の詳細は、​<a href="#cron_expressions">Cron 式</a>​を参照してください。例: <code>expression="1 1 1 1,7 * ?"</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><strong>Time Zone (タイムゾーン)</strong></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>timeZone</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>システムプロパティとして渡されるタイムゾーン、またはマシンのオペレーティングシステムで設定されているタイムゾーン。  <a href="https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html" target="_blank" rel="noopener">Java のタイムゾーン</a>​の値がサポートされます。Java の短縮表記 (​<code>PST</code>​ や ​<code>AGT</code>​) は使用せず、Java の完全表記 (​<code>America/Los_Angeles</code>​ など) を使用してください。例: <code>timeZone="America/Argentina/Buenos_Aires"</code></p>
</div></div></td>
</tr>
</tbody>
</table>

次の例では、​`America/Los_Angeles`​ タイムゾーンで毎日 12 時 00 分にフローをトリガーする Cron 式を使用します。

```xml
<flow name="componentsFlow">
  <scheduler>
    <scheduling-strategy>
      <cron expression="0 0 12 * * ?" timeZone="America/Los_Angeles"/>
    </scheduling-strategy>
  </scheduler>
  <logger message="my message"/>
</flow>
```

## [](#cron_expressions)Cron 式

Cron は、日時情報を記述するのに広く利用されている標準です。Cron 式 (​`<cron expression />`​ スケジュール戦略 (​`<scheduling-strategy >`​) は、固定頻度スケジュール戦略では不可能な間隔でフローをトリガーする場合に便利です。

Scheduler は、毎秒を監視し、Quartz Cron 式が日時の設定と一致すると Mule イベントを作成します。イベントは 1 回だけ、または一定間隔でトリガーできます。

日時の式は、6 つの必須設定と、年の設定 (省略可能) で構成されます。設定は以下の順序で指定します。

1. 秒 (​`0`​-​`59`​)
2. 分 (​`0`​-​`59`​)
3. 時 (​`0`​-​`23`​)
4. 日 (​`1`​-​`31`​)
5. 月 (​`1`​-​`12`​ または ​`JAN`​-​`DEC`​)
6. 曜日 (​`1`​-​`7`​ or ​`SUN`​-​`SAT`​)
7. 年 (空白、または ​`1970`​-​`2099`​ の範囲内の 4 桁。例: `2019`​)

Scheduler は Quartz Cron 式をサポートします。例をいくつか示します。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">式</th>
<th class="tableblock halign-left valign-top">動作</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>1/2 * * * * ?</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">毎日 2 秒おきに実行。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>0 15 10 ? * *</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">毎日午前 10 時 15 分に実行。  <code>0 15 10 * * ? <strong></strong></code><strong>​</strong>` と <code>​0 15 10 *​`0 15 10 * * ?</code>​ は同じ結果になります。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>0 15 10 * * ? 2019</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2019 年の毎日午前 10 時 15 分に実行。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>0 * 14 * * ?</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">毎日午後 2 時から 2 時 59 分まで、毎分実行。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>0 0/5 14 * * ?</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">毎日午後 2 時から 2 時 55 分まで、5 分おきに実行。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>1 1 1 1,7 * ?</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">毎月 1 日と 7 日の午前 1 時 1 分 1 秒に実行。</p></td>
</tr>
</tbody>
</table>

Scheduler コンポーネントは、Quartz Scheduler の特殊文字もサポートします。

- `*`​: すべての値。
- `?`​: 任意の 1 つの値。
- `-`​: 値の範囲。例: `1-3`​。
- `,`​: 追加の値。例: `1,7`​。
- `/`​: 増分値。例: `1/7`​。
- `L`​: 週または月の最終日、または月の最後の特定の曜日 (例: `6L`​ は月の最後の土曜日)。
- `W`​: 平日。日付項目で有効で、特定の日付以降になります。例: `15W`​ はその月の 15 日に最も近い平日を表します。
- `#`​: 月の "n" 日目。例: `#3`​ は月の 3 日。

詳細は、 [「CronExpression」](https://www.quartz-scheduler.org/api/2.3.0/org/quartz/CronExpression.html)​を参照してください。

次の例は、「hello」というメッセージを毎秒ログに記録します。

```XML
<flow name="cronFlow" >
  <scheduler doc:name="Scheduler" >
    <scheduling-strategy >
      <cron expression="* * * * * ?" />
    </scheduling-strategy>
  </scheduler>
  <logger level="INFO" doc:name="Logger" message='"hello"'/>
</flow>
```

Cron 式をビルドするための無料のオンラインツールがたくさんあります。

## [](#anypoint-exchange-での例)Anypoint Exchange での例

[Anypoint Exchange](https://www.mulesoft.com/exchange/)​ での次の例は、Scheduler コンポーネントのユースケースを示しています。

- _Data Sync Using Watermarking and Batch (ウォーターマークとバッチを使用したデータの同期)_
- _Import Contacts into Microsoft Dynamics CRM (Microsoft Dynamics CRM への取引先責任者のインポート)_
- _Import Leads into Salesforce (Salesforce へのリードのインポート)_
- _Importing a CSV File into mongoDB (mongoDB への CSV ファイルのインポート)_
- _Importing an Email Attachment Using the IMAP Connector (IMAP Connector を使用したメールの添付ファイルのインポート)_
- _Salesforce to MySQL Database Using Batch Processing (バッチ処理を使用した Salesforce から MySQL データベースへのインポート)_
- _Sending a CSV File Through Email Using SMTP (SMTP を使用したメールでの CSV ファイルの送信)_

Anypoint Studio からプロジェクトをダウンロードして開くには、[Import a Mule Project from Exchange](https://docs.mulesoft.com/studio/import-project-exchange)を参照してください。

## [](#anypoint-studio-でのデバッグ)Anypoint Studio でのデバッグ

Anypoint Studio の​[デバッグモード](https://docs.mulesoft.com/studio/visual-debugger-concept)​では、Mule アプリケーションはイベントをトリガーできません。デバッグ時に、たとえば次のようにコンポーネントの下に表示される Studio の緑色の矢印アイコンをクリックすることで Scheduler を手動実行できます。

![Scheduler での \[Debug (デバッグ)](/mulesoft/current/ja-jp/mule-runtime/4.5/_images/scheduler-component-debug-ex.png) 矢印\]

## [](#関連情報)関連情報

- [Flow および Subflow スコープ](https://docs.mulesoft.com/jp/mule-runtime/4.5/flow-component)