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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Łukasz Nowak
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
import
json
import
httplib
import
os
import
shutil
import
socket
import
subprocess
import
sys
...
...
@@ -109,15 +110,34 @@ def main():
print
content
with
open
(
args
.
logfile
[
0
],
'a'
)
as
file_
:
cvsfile
=
csv
.
writer
(
file_
)
cvsfile
.
writerow
([
# Write feed safely
error_message
=
""
temp_file
=
args
.
logfile
[
0
]
+
'.tmp'
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
()),
args
.
title
[
0
],
content
,
'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
:
sys
.
exit
(
exit_code
)
...
...
@@ -143,7 +163,6 @@ def main():
notification_path
+=
str
(
transaction_id
)
headers
=
{
'Content-Type'
:
feed
.
info
().
getheader
(
'Content-Type'
)}
error_message
=
""
try
:
notification
=
httplib
.
HTTPConnection
(
notification_url
.
hostname
,
notification_port
)
...
...
@@ -160,7 +179,7 @@ def main():
finally
:
if
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
:
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