我想知道是否可以通过HTTP请求获得气流任务。我对Airflow的调度部分不感兴趣。我只是想用它代替Celery。
I wanted to know if airflow tasks can be executed upon getting a request over HTTP. I am not interested in the scheduling part of Airflow. I just want to use it as a substitute for Celery.
因此,示例操作就是这样。
So an example operation would be something like this.
根据我在网上阅读的内容,可以通过在命令行上执行 airflow ... 来运行气流作业。我想知道是否有可以执行相同操作的python API。
From whatever I read online, you can run airflow jobs by executing airflow ... on the command line. I was wondering if there is a python api which can execute the same thing.
谢谢。
推荐答案Airflow REST API插件将为您提供帮助这里。按照说明安装插件后,您只需点击以下网址: http:// {HOST}:{PORT} /admin/rest_api/api/v1.0/trigger_dag? dag_id = {dag_id}& run_id = {run_id}& conf = {url_encoded_json_parameters} ,将dag_id替换为dag的ID,忽略run_id或指定唯一的ID,并传递经过编码的url conf的json(使用触发的dag中需要的任何参数)。
The Airflow REST API Plugin would help you out here. Once you have followed the instructions for installing the plugin you would just need to hit the following url: {HOST}:{PORT}/admin/rest_api/api/v1.0/trigger_dag?dag_id={dag_id}&run_id={run_id}&conf={url_encoded_json_parameters}, replacing dag_id with the id of your dag, either omitting run_id or specify a unique id, and passing a url encoded json for conf (with any of the parameters you need in the triggered dag).
以下是使用jQuery调用Airflow api的JavaScript函数示例:
Here is an example JavaScript function that uses jQuery to call the Airflow api:
function triggerDag(dagId, dagParameters){ var urlEncodedParameters = encodeURIComponent(dagParameters); var dagRunUrl = "airflow:8080/admin/rest_api/api/v1.0/trigger_dag?dag_id="+dagId+"&conf="+urlEncodedParameters; $.ajax({ url: dagRunUrl, dataType: "json", success: function(msg) { console.log('Successfully started the dag'); }, error: function(e){ console.log('Failed to start the dag'); } }); }更多推荐
基于Webrequest在气流上运行作业
发布评论