-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatcher_caronte.jl
57 lines (51 loc) · 1.55 KB
/
watcher_caronte.jl
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using ArgParse
using Rembus
const DEFAULT_FOLDER = "src"
function command_line()
s = ArgParseSettings()
@add_arg_table! s begin
"--watchdir"
help = "source directory to watch"
arg_type = String
default = DEFAULT_FOLDER
"--reset", "-r"
help = "factory reset, clean up broker configuration"
action = :store_true
"--debug", "-d"
help = "enable debug logs"
action = :store_true
end
return parse_args(s)
end
function watch_task(pd, wdir)
try
@info "watch_task start, watchdir: [$wdir]"
router = Rembus.get_router()
prev_paths = []
while true
files = readdir(wdir)
sleep(0.2)
for fn in files
fpath = joinpath(wdir, fn)
if fn === "foo"
rm(fpath, force=true)
error("harakiri")
end
try
content = read(fpath)
publish(router, "pollution", [basename(fn), content])
rm(fpath, force=true)
catch e
@info "error: $e, retrying ..."
end
end
end
catch e
@error "watch_task: $e"
showerror(stdout, e, stacktrace())
end
@info "watch_task done"
end
args = command_line()
sv = caronte(wait=false, args=merge(args, Dict("http" => 9000)))
startup(process(watch_task, args=(args["watchdir"],), restart=:permanent))