/
queue.go
42 lines (38 loc) · 833 Bytes
/
queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"time"
)
type queue struct {
todo map[string]bool
dircap string
db *_db
}
func init_queue(dircap string, db *_db) queue {
var q queue
q.dircap = dircap
q.db = db
m := make(map[string]bool)
q.todo = m
return q
}
func (q queue) add(file string, action string) {
if val := q.todo[file]; !val {
q.todo[file] = true
fmt.Printf("Blocking any more actions on %s\n", file)
go func() {
time.Sleep(time.Minute)
if action == "NEW" {
new_upload(q.dircap, file, q.db)
} else if action == "UPDATE" {
upload(q.dircap, file, q.db)
} else if action == "DELETE" {
delete(q.dircap, file, q.db)
}
q.todo[file] = false
fmt.Printf("Now accepting actions on %s\n", file)
}()
} else {
fmt.Printf("Received action %s but file %s is blocked.\n", action, file)
}
}