airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AIRFLOW-2836) Minor improvement of contrib.sensors.FileSensor
Date Fri, 03 Aug 2018 13:48:00 GMT

    [ https://issues.apache.org/jira/browse/AIRFLOW-2836?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16568223#comment-16568223
] 

ASF GitHub Bot commented on AIRFLOW-2836:
-----------------------------------------

Fokko closed pull request #3674: [AIRFLOW-2836] Minor improvement of contrib.sensors.FileSensor
URL: https://github.com/apache/incubator-airflow/pull/3674
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/contrib/sensors/file_sensor.py b/airflow/contrib/sensors/file_sensor.py
index 3f7bb24e08..3e49abdfb5 100644
--- a/airflow/contrib/sensors/file_sensor.py
+++ b/airflow/contrib/sensors/file_sensor.py
@@ -46,7 +46,7 @@ class FileSensor(BaseSensorOperator):
     @apply_defaults
     def __init__(self,
                  filepath,
-                 fs_conn_id='fs_default2',
+                 fs_conn_id='fs_default',
                  *args,
                  **kwargs):
         super(FileSensor, self).__init__(*args, **kwargs)
@@ -56,7 +56,7 @@ def __init__(self,
     def poke(self, context):
         hook = FSHook(self.fs_conn_id)
         basepath = hook.get_path()
-        full_path = "/".join([basepath, self.filepath])
+        full_path = os.path.join(basepath, self.filepath)
         self.log.info('Poking for file {full_path}'.format(**locals()))
         try:
             if stat.S_ISDIR(os.stat(full_path).st_mode):
diff --git a/tests/contrib/sensors/test_file_sensor.py b/tests/contrib/sensors/test_file_sensor.py
index d78400e317..0bb0007c60 100644
--- a/tests/contrib/sensors/test_file_sensor.py
+++ b/tests/contrib/sensors/test_file_sensor.py
@@ -125,6 +125,18 @@ def test_file_in_dir(self):
         finally:
             shutil.rmtree(dir)
 
+    def test_default_fs_conn_id(self):
+        with tempfile.NamedTemporaryFile() as tmp:
+            task = FileSensor(
+                task_id="test",
+                filepath=tmp.name[1:],
+                dag=self.dag,
+                timeout=0,
+            )
+            task._hook = self.hook
+            task.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE,
+                     ignore_ti_state=True)
+
 
 if __name__ == '__main__':
     unittest.main()


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Minor improvement of contrib.sensors.FileSensor
> -----------------------------------------------
>
>                 Key: AIRFLOW-2836
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-2836
>             Project: Apache Airflow
>          Issue Type: Improvement
>          Components: contrib
>            Reporter: Xiaodong DENG
>            Assignee: Xiaodong DENG
>            Priority: Minor
>
> h4. *Background*
> The default *fs_conn_id* in contrib.sensors.FileSensor is '_*fs_default2*_'. However,
when we initiate the database (https://github.com/apache/incubator-airflow/blob/master/airflow/utils/db.py#L88),
there isn't such an entry. It doesn't exist anywhere else.
> h4. *Issue*
> The purpose of _contrib.sensors.FileSensor_ is mainly for checking local file system
(of course can also be used for NAS). Then the path ("/") from default connection 'fs_default'
would suffice.
> However, given the default value for *fs_conn_id* in contrib.sensors.FileSensor is
"fs_default2" (a value doesn't exist), it will make the situation much more complex. 
> When users intend to check local file system only, they should be able to leave *fs_conn_id* default
directly, instead of going setting up another connection separately.
> h4. Proposal
> Change default value for *fs_conn_id* in contrib.sensors.FileSensor from "fs_default2"
to "fs_default" (actually in the related test, the *fs_conn_id* are all specified to be "fs_default").



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message