@@ -27,10 +27,32 @@ def copy
2727
2828 def send_file
2929 validate_filename
30+ return if file . blank?
31+
3032 create_subdirs ( path )
33+
34+ with_timeout do
35+ client . files . upload_file ( share , path , name , file )
36+ end
37+ end
38+
39+ def delete_file
40+ validate_filename
41+
42+ with_timeout do
43+ client . files . delete_file ( share , path , name )
44+ end
45+ end
46+
47+ def copy_file ( new_path )
48+ validate_filename
3149 return if file . blank?
3250
33- upload_with_timeout
51+ create_subdirs ( new_path )
52+
53+ with_timeout do
54+ client . files . copy_file ( share , path , name , share , new_path , name )
55+ end
3456 end
3557
3658 def create_subdirs ( current_path )
@@ -44,17 +66,6 @@ def create_subdirs(current_path)
4466 end
4567 end
4668
47- def delete_file
48- client . files . delete_file ( share , path , name )
49- end
50-
51- def copy_file ( new_path )
52- create_subdirs ( new_path )
53- return if file . blank?
54-
55- client . files . copy_file ( share , path , name , share , new_path , name )
56- end
57-
5869 def client
5970 @client ||= AzureFileShares . client
6071 end
@@ -69,9 +80,9 @@ def validate_filename
6980 Rails . logger . warn "[FileWorker] Provider should be renamed to avoid these characters: /\\ <>:\" |?*"
7081 end
7182
72- def upload_with_timeout
83+ def with_timeout ( & block )
7384 Timeout . timeout ( UPLOAD_TIMEOUT , Timeout ::Error , "Azure FileShares upload timed out after #{ UPLOAD_TIMEOUT } seconds" ) do
74- client . files . upload_file ( share , path , name , file )
85+ block . call
7586 end
7687 rescue Timeout ::Error => e
7788 Rails . logger . error "[FileWorker] Upload timeout: #{ e . message } "
0 commit comments