Alteryxのワークフローをコマンドラインから実行する #alteryx #22 | Alteryx Advent Calendar 2016

2016.12.22

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは。yokatsukiです。

当エントリは『Alteryx Advent Calendar 2016』の22日目のエントリです。

今回はAlteryxのワークフローをコマンドラインから実行する方法について紹介します。

はじめに

Alteryx Designerのワークフローは、DesignerのGUI画面で作成し、Run Workflowボタン(下記)から実行するのが普通です。

alteryx-advent-calendar-22-exec-alteryx-workflow-from-cli-01

しかし定期的に繰り返し実行したい時など、バッチ処理として組み込むにはGUI操作は不向きですね。そこで、Alteryxには、予めコマンドラインで実行するための機能が用意されています。

こちらを使ってワークフローを実行する方法を確認します。動作確認は、以下の環境で行いました。

  • Windows 10 Pro バージョン1607
  • Alteryx Designer x64 Version: 10.6.7.17850

試してみた

まず最初に、ドキュメントの記述を確認します。

The AlteryxEngineCmd.exe is located in the Alteryx root directory and requires an Engine API license to use.

実行コマンドであるAlteryxEngineCmd.exeは、実際にはAlteryxをインストールしたディレクトリ下のサブディレクトリbinに配置されています。また、動作させる際には関連する.dllファイル群が同じディレクトリに必要なので、このbinディレクトリに予めPATHを通しておくと良いと思います。

C:\>set PATH=C:\Program Files\Alteryx\bin;%PATH%

C:\>AlteryxEngineCmd
AlteryxEngineCmd.exe Version 10.6.8.17850 c Alteryx, Inc. - All Rights Reserved.

Usage:
AlteryxEngineCmd MyModule.yxmd

or
AlteryxEngineCmd MyAnalyticApp.yxwz AnalyticAppValues.xml

or
AlteryxEngineCmd AnalyticAppValues.xml
Runs the Analytic App contained in the Path tag of AnalyticAppValues.xml

or
AlteryxEngineCmd /Encrypt Mymodule.yxwz Output.yxwz [CommaSeparatedSerialNumbers [ExpirationDate]]

Returns: 0 - Success, 1 - Warnings Exist, 2 - Errors Exist

それからもう一つ、ライセンスについての記述があります。コマンド実行させる際には、Engine API追加のライセンスが必要です。 ライセンスの取得状況は、メニューバーの[Options] - [Manage Licenses]操作で確認することができます。

alteryx-advent-calendar-22-exec-alteryx-workflow-from-cli-02

参考までに、まずはEngine APIライセンスがない状態で、Alteryxのサンプルワークフローファイル"Frequently_Used_Tools.yxmd"を動作させてみます。これは、ワークフローファイルから相対パスで指定された位置にある1500件のCSVファイルを読み込んで、最終的に10件のデータを抽出するというものです。

C:\>AlteryxEngineCmd "C:\Program Files\Alteryx\Samples\03 Basics\Frequently_Used_Tools.yxmd"
AlteryxEngineCmd.exe Version 10.6.8.17850 c Alteryx, Inc. - All Rights Reserved.
Started running C:\Program Files\Alteryx\Samples\03 Basics\Frequently_Used_Tools.yxmd
Error - Alteryx Engine: The Feature "API" is not licensed.
Finished in 0.1 seconds with 1 error

ライセンスがないと、実行時にこのようなエラーが出ます。今度はライセンスを追加して再実行します。

C:\>AlteryxEngineCmd "C:\Program Files\Alteryx\Samples\03 Basics\Frequently_Used_Tools.yxmd"
AlteryxEngineCmd.exe Version 10.6.8.17850 c Alteryx, Inc. - All Rights Reserved.
Started running C:\Program Files\Alteryx\Samples\03 Basics\Frequently_Used_Tools.yxmd
ToolId 1: C:\Program Files\Alteryx\Samples\SampleData\CSVGeocode_example.csv|1500 records were read from "C:\Program Files\Alteryx\Samples\SampleData\CSVGeocode_example.csv"
ToolId 15: 1491 unique records and 9 duplicates were found
ToolId 5: 1491 records were summarized to 354 groups
ToolId 6: 1491 records were joined with 0 un-joined left records and 0 un-joined right records
ToolId 8: 665 records were True and 826 were False
ToolId 38: 10 records were output
Finished in 0.2 seconds

実行できました。ワークフローファイルを起点にした相対パスの設定でも、正しく入力のCSVファイルへアクセスできています。

まとめ

コマンドラインからAlteryxのワークフローを実行してみました。実行には追加ライセンスが必要という点がハードル高いですが、定形処理を自動化する為の方法として、ここで紹介した方法もあるということをご承知おき頂ければ嬉しいです。

また、引数を取るワークフローアプリケーション(.yxwz)の操作法については、別途XMLファイルを準備する必要があるのですが、それについてはまた別のエントリで紹介したいと思います。

明日23日目は再びk.ootakiさんによる『パース系ツールについてさわってみた』の予定です。

明日もお楽しみに!