File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed
providers/google/cloud/sensors
tests/system/providers/google/cloud/gcs Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -241,7 +241,7 @@ class GCSUploadSessionCompleteSensor(BaseSensorOperator):
241
241
"""
242
242
Checks for changes in the number of objects at prefix in Google Cloud Storage
243
243
bucket and returns True if the inactivity period has passed with no
244
- increase in the number of objects. Note, this sensor will no behave correctly
244
+ increase in the number of objects. Note, this sensor will not behave correctly
245
245
in reschedule mode, as the state of the listed objects in the GCS bucket will
246
246
be lost between rescheduled invocations.
247
247
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ class BaseSensorOperator(BaseOperator, SkipMixin):
81
81
82
82
:param soft_fail: Set to true to mark the task as SKIPPED on failure
83
83
:param poke_interval: Time in seconds that the job should wait in
84
- between each tries
84
+ between each try
85
85
:param timeout: Time, in seconds before the task times out and fails.
86
86
:param mode: How the sensor operates.
87
87
Options are: ``{ poke | reschedule }``, default is ``poke``.
Original file line number Diff line number Diff line change 47
47
UPLOAD_FILE_PATH = str (Path (__file__ ).parent / "resources" / FILE_NAME )
48
48
49
49
50
+ def workaround_in_debug_executor (cls ):
51
+ """
52
+ DebugExecutor change sensor mode from poke to reschedule. Some sensors don't work correctly
53
+ in reschedule mode. They are decorated with `poke_mode_only` decorator to fail when mode is changed.
54
+ This method creates dummy property to overwrite it and force poke method to always return True.
55
+ """
56
+ cls .mode = dummy_mode_property ()
57
+ cls .poke = lambda self , ctx : True
58
+
59
+
60
+ def dummy_mode_property ():
61
+ def mode_getter (self ):
62
+ return self ._mode
63
+
64
+ def mode_setter (self , value ):
65
+ self ._mode = value
66
+
67
+ return property (mode_getter , mode_setter )
68
+
69
+
50
70
with models .DAG (
51
71
DAG_ID ,
52
72
schedule = '@once' ,
58
78
task_id = "create_bucket" , bucket_name = BUCKET_NAME , project_id = PROJECT_ID
59
79
)
60
80
81
+ workaround_in_debug_executor (GCSUploadSessionCompleteSensor )
82
+
61
83
# [START howto_sensor_gcs_upload_session_complete_task]
62
84
gcs_upload_session_complete = GCSUploadSessionCompleteSensor (
63
85
bucket = BUCKET_NAME ,
89
111
gcs_object_exists = GCSObjectExistenceSensor (
90
112
bucket = BUCKET_NAME ,
91
113
object = FILE_NAME ,
92
- mode = 'poke' ,
93
114
task_id = "gcs_object_exists_task" ,
94
115
)
95
116
# [END howto_sensor_object_exists_task]
98
119
gcs_object_with_prefix_exists = GCSObjectsWithPrefixExistenceSensor (
99
120
bucket = BUCKET_NAME ,
100
121
prefix = FILE_NAME [:5 ],
101
- mode = 'poke' ,
102
122
task_id = "gcs_object_with_prefix_exists_task" ,
103
123
)
104
124
# [END howto_sensor_object_with_prefix_exists_task]
You can’t perform that action at this time.
0 commit comments