-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapi.jl
58 lines (42 loc) · 1.39 KB
/
webapi.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
58
include("packing.jl")
using Genie, Genie.Renderer.Json, Genie.Requests, HTTP
using UUIDs
#using Logging
# Set the global logging level to Warn
#global_logger(ConsoleLogger(stderr, Logging.Warn))
instances = Dict()
route("/simulations", method=POST) do
payload = jsonpayload()
model, pathfinder = initialize_model()
id = string(uuid1())
instances[id] = model
agents = []
for robots in allagents(model)
push!(agents, robots)
end
sort!(agents, by=x -> x.id)
# println(size(queue_cajas))
json(Dict("Location" => "/simulations/$id", "agents" => agents, "queue_front" => first(queue_cajas)))
end
route("/simulations/:id") do
#println(payload(:id))
model = instances[payload(:id)]
run!(model, 1)
agents = []
for robots in allagents(model)
push!(agents, robots)
end
sort!(agents, by=x -> x.id)
if (!isempty(queue_cajas))
json(Dict("agents" => agents, "queue_front" => first(queue_cajas)))
else
json(Dict("agents" => agents, "queue_front" => -1))
end
# json(Dict("agents" => agents))
end
Genie.config.run_as_server = true
Genie.config.cors_headers["Access-Control-Allow-Origin"] = "*"
Genie.config.cors_headers["Access-Control-Allow-Headers"] = "Content-Type"
Genie.config.cors_headers["Access-Control-Allow-Methods"] = "GET,POST,PUT,DELETE,OPTIONS"
Genie.config.cors_allowed_origins = ["*"]
up()