16
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
#
18
18
#########################################################################
19
+ import logging
19
20
import os
20
21
21
22
from django .conf import settings
46
47
47
48
logger = get_task_logger (__name__ )
48
49
50
+ log_lock = logging .getLogger ("geonode_lock_handler" )
51
+
49
52
50
53
@app .task (
51
54
bind = True ,
@@ -65,12 +68,16 @@ def geoserver_update_datasets(self, *args, **kwargs):
65
68
Runs update layers.
66
69
"""
67
70
lock_id = f'{ self .request .id } '
71
+ log_lock .debug (f"geoserver_update_datasets: Creating lock { lock_id } " )
68
72
with AcquireLock (lock_id ) as lock :
73
+ log_lock .debug (f"geoserver_update_datasets: Acquiring lock { lock_id } " )
69
74
if lock .acquire () is True :
75
+ log_lock .debug (f"geoserver_update_datasets: Acquired lock { lock_id } " )
70
76
try :
71
77
return gs_slurp (* args , ** kwargs )
72
78
finally :
73
79
lock .release ()
80
+ log_lock .debug (f"geoserver_update_datasets: Released lock { lock_id } " )
74
81
75
82
76
83
@app .task (
@@ -100,9 +107,12 @@ def geoserver_set_style(
100
107
logger .debug (f"Dataset id { instance_id } does not exist yet!" )
101
108
raise
102
109
103
- lock_id = f'{ self .request .id } '
110
+ lock_id = f'{ self .request .id } ' if self .request .id else instance .name
111
+ log_lock .debug (f"geoserver_set_style: Creating lock { lock_id } for { instance .name } " )
104
112
with AcquireLock (lock_id ) as lock :
113
+ log_lock .debug (f"geoserver_set_style: Acquiring lock { lock_id } for { instance .name } " )
105
114
if lock .acquire () is True :
115
+ log_lock .debug (f"geoserver_set_style: Acquired lock { lock_id } for { instance .name } " )
106
116
try :
107
117
sld = open (base_file , "rb" ).read ()
108
118
set_dataset_style (
@@ -114,6 +124,7 @@ def geoserver_set_style(
114
124
logger .exception (e )
115
125
finally :
116
126
lock .release ()
127
+ log_lock .debug (f"geoserver_set_style: Released lock { lock_id } for { instance .name } " )
117
128
118
129
119
130
@app .task (
@@ -146,9 +157,12 @@ def geoserver_create_style(
146
157
logger .debug (f"Dataset id { instance_id } does not exist yet!" )
147
158
raise
148
159
149
- lock_id = f'{ self .request .id } '
160
+ lock_id = f'{ self .request .id } ' if self .request .id else instance .name
161
+ log_lock .debug (f"geoserver_create_style: Creating lock { lock_id } for { instance .name } " )
150
162
with AcquireLock (lock_id ) as lock :
151
- if lock .acquire () is True and instance :
163
+ log_lock .debug (f"geoserver_create_style: Acquiring lock { lock_id } for { instance .name } " )
164
+ if lock .acquire () is True :
165
+ log_lock .debug (f"geoserver_create_style: Acquired lock { lock_id } for { instance .name } " )
152
166
try :
153
167
f = None
154
168
if sld_file and os .path .exists (sld_file ) and os .access (sld_file , os .R_OK ):
@@ -194,6 +208,7 @@ def geoserver_create_style(
194
208
geoserver_automatic_default_style_set .send_robust (sender = instance , instance = instance )
195
209
finally :
196
210
lock .release ()
211
+ log_lock .debug (f"geoserver_create_style: Released lock { lock_id } for { instance .name } " )
197
212
198
213
199
214
@app .task (
@@ -216,9 +231,19 @@ def geoserver_post_save_datasets(
216
231
"""
217
232
Runs update layers.
218
233
"""
219
- lock_id = f'{ self .request .id } '
234
+ instance = None
235
+ try :
236
+ instance = Dataset .objects .get (id = instance_id )
237
+ except Dataset .DoesNotExist :
238
+ logger .debug (f"Dataset id { instance_id } does not exist yet!" )
239
+ raise
240
+
241
+ lock_id = f'{ self .request .id } ' if self .request .id else instance .name
242
+ log_lock .debug (f"geoserver_post_save_datasets: Creating lock { lock_id } for { instance_id } " )
220
243
with AcquireLock (lock_id ) as lock :
244
+ log_lock .debug (f"geoserver_post_save_datasets: Acquiring lock { lock_id } for { instance_id } " )
221
245
if lock .acquire () is True :
246
+ log_lock .debug (f"geoserver_post_save_datasets: Acquired lock { lock_id } for { instance_id } " )
222
247
try :
223
248
sync_instance_with_geoserver (instance_id , * args , ** kwargs )
224
249
@@ -227,6 +252,7 @@ def geoserver_post_save_datasets(
227
252
call_command ('update_index' )
228
253
finally :
229
254
lock .release ()
255
+ log_lock .debug (f"geoserver_post_save_datasets: Releasing lock { lock_id } for { instance_id } " )
230
256
231
257
232
258
@app .task (
@@ -253,9 +279,12 @@ def geoserver_create_thumbnail(self, instance_id, overwrite=True, check_bbox=Tru
253
279
logger .error (f"Resource id { instance_id } does not exist yet!" )
254
280
raise
255
281
256
- lock_id = f'{ self .request .id } '
282
+ lock_id = f'{ self .request .id } ' if self .request .id else instance .name
283
+ log_lock .debug (f"geoserver_create_thumbnail: Creating lock { lock_id } for { instance .name } " )
257
284
with AcquireLock (lock_id ) as lock :
285
+ log_lock .debug (f"geoserver_create_thumbnail: Acquiring lock { lock_id } for { instance .name } " )
258
286
if lock .acquire () is True :
287
+ log_lock .debug (f"geoserver_create_thumbnail: Acquired lock { lock_id } for { instance .name } " )
259
288
try :
260
289
instance .set_processing_state (enumerations .STATE_RUNNING )
261
290
try :
@@ -268,6 +297,7 @@ def geoserver_create_thumbnail(self, instance_id, overwrite=True, check_bbox=Tru
268
297
instance .set_processing_state (enumerations .STATE_PROCESSED )
269
298
finally :
270
299
lock .release ()
300
+ log_lock .debug (f"geoserver_create_thumbnail: Released lock { lock_id } for { instance .name } " )
271
301
272
302
273
303
@app .task (
0 commit comments