mirror of
https://github.com/Luzifer/tex-api.git
synced 2024-11-08 16:20:04 +00:00
Use atomic operations to update status
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
e2da6ba41f
commit
4bcb077fbf
1 changed files with 14 additions and 6 deletions
12
main.go
12
main.go
|
@ -44,6 +44,7 @@ const (
|
|||
const (
|
||||
filenameInput = "input.zip"
|
||||
filenameStatus = "status.json"
|
||||
filenameStatusTemp = "status.tmp.json"
|
||||
filenameOutputDir = "output"
|
||||
sleepBase = 1.5
|
||||
)
|
||||
|
@ -79,13 +80,20 @@ func (s *jobStatus) UpdateStatus(st status) {
|
|||
|
||||
func (s jobStatus) Save() error {
|
||||
uid, _ := uuid.FromString(s.UUID) // #nosec G104
|
||||
f, err := os.Create(pathFromUUID(uid, filenameStatus))
|
||||
f, err := os.Create(pathFromUUID(uid, filenameStatusTemp))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return json.NewEncoder(f).Encode(s)
|
||||
if err = json.NewEncoder(f).Encode(s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.Rename(
|
||||
pathFromUUID(uid, filenameStatusTemp),
|
||||
pathFromUUID(uid, filenameStatus),
|
||||
)
|
||||
}
|
||||
|
||||
func urlMust(u *url.URL, err error) *url.URL {
|
||||
|
|
Loading…
Reference in a new issue