Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.toolbox
Commits
89ad1d9e
Commit
89ad1d9e
authored
Nov 29, 2016
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notifier: write feed in a transactional way, to avoid corrupted feed
parent
e212d72c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
11 deletions
+30
-11
slapos/pubsub/notifier.py
slapos/pubsub/notifier.py
+30
-11
No files found.
slapos/pubsub/notifier.py
View file @
89ad1d9e
...
@@ -7,6 +7,7 @@ import datetime
...
@@ -7,6 +7,7 @@ import datetime
import
json
import
json
import
httplib
import
httplib
import
os
import
os
import
shutil
import
socket
import
socket
import
subprocess
import
subprocess
import
sys
import
sys
...
@@ -109,15 +110,34 @@ def main():
...
@@ -109,15 +110,34 @@ def main():
print
content
print
content
# Write feed safely
with
open
(
args
.
logfile
[
0
],
'a'
)
as
file_
:
error_message
=
""
cvsfile
=
csv
.
writer
(
file_
)
temp_file
=
args
.
logfile
[
0
]
+
'.tmp'
cvsfile
.
writerow
([
try
:
shutil
.
copy2
(
args
.
logfile
[
0
],
temp_file
)
except
IOError
:
error_message
=
"ERROR ON WRITING FEED"
try
:
with
open
(
temp_file
,
'a'
)
as
file_
:
csvfile
=
csv
.
writer
(
file_
)
csvfile
.
writerow
([
int
(
time
.
time
()),
int
(
time
.
time
()),
args
.
title
[
0
],
args
.
title
[
0
],
content
,
content
,
'slapos:%s'
%
uuid
.
uuid4
(),
'slapos:%s'
%
uuid
.
uuid4
(),
])
])
os
.
rename
(
temp_file
,
args
.
logfile
[
0
])
except
:
error_message
=
"ERROR ON WRITING FEED"
finally
:
try
:
os
.
remove
(
temp_file
)
except
OSError
:
pass
if
error_message
:
saveStatus
(
error_message
)
exit_code
=
1
if
exit_code
!=
0
:
if
exit_code
!=
0
:
sys
.
exit
(
exit_code
)
sys
.
exit
(
exit_code
)
...
@@ -143,7 +163,6 @@ def main():
...
@@ -143,7 +163,6 @@ def main():
notification_path
+=
str
(
transaction_id
)
notification_path
+=
str
(
transaction_id
)
headers
=
{
'Content-Type'
:
feed
.
info
().
getheader
(
'Content-Type'
)}
headers
=
{
'Content-Type'
:
feed
.
info
().
getheader
(
'Content-Type'
)}
error_message
=
""
try
:
try
:
notification
=
httplib
.
HTTPConnection
(
notification_url
.
hostname
,
notification
=
httplib
.
HTTPConnection
(
notification_url
.
hostname
,
notification_port
)
notification_port
)
...
@@ -160,7 +179,7 @@ def main():
...
@@ -160,7 +179,7 @@ def main():
finally
:
finally
:
if
error_message
:
if
error_message
:
sys
.
stderr
.
write
(
error_message
)
sys
.
stderr
.
write
(
error_message
)
saveStatus
(
saveStatus
(
'ERROR ON NOTIFYING : %s'
)
%
error_message
)
saveStatus
(
'ERROR ON NOTIFYING : %s'
)
%
error_message
if
some_notification_failed
:
if
some_notification_failed
:
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment