イベント

Version 26.1.9516


イベント


多くの場合、ユーザーは外部情報をデータフロータスクに統合する必要があります。CData Sync は、そのようなシナリオを可能にするジョブ前およびジョブ後の両イベントを提供します。これらのイベントを使用すると、Sync アプリケーションに含まれるXML ベース言語APIScript を使用して、クエリパラメータを挿入したり、他の外部の処理をトリガーしたりできます。

バッチファイルの実行、E メール送信、新しいジョブの実行のトリガーなどの一般的なアクションを自動化するための完全なコードスニペットがSync に含まれています。ジョブのイベント タブで、スニペットを挿入 をクリックして、実行するアクションを選択します。必要なコードがカーソルに挿入されています。

Pre-Job イベント

pre-job イベントは、ジョブがクエリの実行を開始する前に発生します。ジョブの名前、データソース、同期先などを含むジョブに関する詳細は、イベントスクリプト内でロジカルな選択を行うために使用できる入力パラメータとして利用できます。また、後でジョブの実行中に使用できる出力項目の属性値をプッシュすることもできます。

<api:info title="Before Run" desc="このイベントはジョブを実行する前に発生します。">
  <input name="JobName"      required="true" desc="実行されるジョブの名前。" />
  <input name="Source"       required="true" desc="データソース接続の名前。" />
  <input name="Destination"  required="true" desc="同期先接続の名前。" />
  <input name="JobStatus"    required="true" desc="以前のジョブのステータス。" />
  <output name="env:*"                       desc="ジョブで後で使用される変数。" />
  <output name="CancelJob"                   desc="ジョブの実行をキャンセルしたい場合はtrue に設定。" />
</api:info>

環境変数を作成

環境変数は、pre-job イベントスクリプトで作成し、ジョブの実行に追加できます。次の例では、現在のタイムスタンプでcurrentTimeStamp 変数を作成し、その値を持つout アイテムをジョブにプッシュします。

<api:set attr="out.env:currenttimestamp"  value="[null | now()]" />
<api:push item="out" />

REPLICATE クエリでの環境変数の使用

REPLICATE クエリ内で、ジョブにプッシュされた環境変数をさまざまな方法で使用できます。環境変数を参照するには、env:attribute を中かっこ({})で囲みます。次の例では、currenttimestamp の値を新しいカラムDateUpdated に設定します。

REPLICATE [Table] SELECT [ID], [Name], '{env:currenttimestamp}' AS [DateUpdated] FROM [Table]

Post-Job イベント

post-job イベントは、ジョブがクエリの実行を完了した後に始まります。インプット項目には、他の操作の呼び出しに使用できるジョブの実行結果が含まれます。

<api:info title="After Run" desc="このイベントはジョブを実行した後に発生します。">
  <input name="JobName"              required="true" desc="実行されるジョブの名前。" />
  <input name="Source"               required="true" desc="データソース接続の名前。" />
  <input name="Destination"          required="true" desc="同期先接続の名前。" />
  <input name="JobStatus"            required="true" desc="完了した実行のステータス。" />
  <input name="RunStartDate"         required="true" desc="ジョブ実行の開始日。" />
  <input name="AffectedRows"         required="true" desc="実行による影響を受けた行の数。" />
  <input name="Details"              required="true" desc="ジョブ実行の詳細。" />
  <input name="FailedQueries"        required="true" desc="失敗したクエリのリスト。" />
  <input name="FailedQueriesCount"   required="true" desc="失敗したクエリの数。" />
  <input name="SuccessQueries"       required="true" desc="成功したクエリのリスト。" />
  <input name="SuccessQueriesCount"  required="true" desc="成功したクエリの数。" />
  <input name="FailedTables"         required="true" desc="失敗したテーブルのリスト。" />
  <input name="RunTime"              required="true" desc="前回のジョブの実行時間。" />
  <input name="Query#"               required="true" desc="実行された各クエリを含む配列。" />
  <input name="QueryStatus#"         required="true" desc="実行された各クエリのステータスを含む配列。" />
</api:info>

ジョブ実行のトリガー

post-job イベントを設定して別のジョブの実行をトリガーできます。例えば、次のコードスニペットは、現在のジョブがクエリの実行を終了した後にJob2 を実行します。api:if キーワードを使用してこの例を拡張し、現在のジョブが成功した場合にのみJob2 を実行することもできます。

<!-- Start Executing different Job -->
<api:set attr="job.JobName"        value="Job2"/>
<api:set attr="job.WorkspaceId"    value="default"/>
<api:set attr="job.ExecutionType"  value="Run"/>
<api:set attr="job.WaitForResults" value="true"/> <!--Setting value=true causes the processing to wait for the job to complete. -->
<api:call op="api.rsc/executeJob" httpmethod="post" authtoken="<YourAPIToken>" in="job"/>

Note: In this example, the job.WorkspaceId attribute identifies the workspace that contains the target job.When you want to trigger a job within the same workspace, set this attribute to default or specify the workspace’s name.When you want to trigger a job in another workspace, provide the name of that workspace.The Insert Snippet option in the Event editor includes the job.WorkspaceId attribute automatically with the value set to default.

This attribute is required in these cases:

  • The workspace for both jobs is the same workspace but is not the default workspace.

  • The initiating job and the target job belong to different workspaces.

If you omit this attribute in such cases, the API call can fail.When a failure occurs, Sync does not display an error message during the save operation or when the job runs.The job status appears as successful, even though the post-job event did not execute as expected.However, an error is recorded in the application logs.To verify whether a post-job event actually succeeded, review the logs after your job runs.

サンプルスクリプトの拡張

このセクションのコードスニペットは、APIScript を使用してできることのほんの一例です。APIScript 言語は完全な計算能力を備えているため、複雑なビジネスロジックを管理できます。

実行フローなどを制御するには、他のAPIScript キーワードを使用できます。このスクリプトには、処理と自動化をアシストする多くの機能拡張と組み込み操作が含まれています。例えば、APIScript はE メールの送信やファイルの移動などのタスクを容易にします。

オペレーションに固有の追加のインプット値を渡すこともできます。

  • appSendEmail オペレーションは、本文、添付ファイル、SSL/TLS プロパティなど、いくつかの追加インプット項目を受け付けます。これらの項目は、api:set キーワードを使用して指定します。

  • api:call キーワードを使用することで、イベント内の任意の組み込み操作を呼び出したり、API を呼び出すこともできます。

詳細情報

APIScript の構文および機能の詳細については、APIScript 入門 を参照してください。