format: 1
id: downloads
version: 2
contracts: [download_manager]
events:
go_online: {}
go_offline: {}
add: { payload: { url: { type: string, required: true } } }
download_done: { payload: { id: { type: string } }, scope: local }
top:
esvs:
max_active: { type: int, init: 3, external: true } active: { type: int, init: 0 }
on_events:
env: action: [ { refresh: { only: [max_active] } } ] download_done:
action: [ { assign: { active: "active - 1" } } ]
initial: { transition_to: offline }
states:
offline:
defer: [add] on_events:
go_online: { transition_to: online }
online:
on_events:
go_offline: { transition_to: offline }
add: guard: "active < max_active"
action:
- spawn: { def: download, payload: { url: "event.payload.url" } }
- assign: { active: "active + 1" }
migrations:
- from: 1
to: 2
when: "state in ['up','down']"
state_map: { up: online, down: offline }
---
format: 1
id: download
version: 1
contracts: [download]
events:
connected: {}
chunk: { payload: { bytes: { type: int, required: true } }, scope: internal }
eof: {}
hash_ok: {}
hash_mismatch: {}
pause: {}
resume: {}
download_done: { payload: { id: { type: string } }, scope: local }
top:
esvs:
bytes_done: { type: int, init: 0 } on_events:
error: { transition_to: failed } initial: { transition_to: active }
states:
active:
type: orthogonal
history: deep
on_events:
pause: { transition_to: paused }
done: { transition_to: complete } regions:
- initial: { transition_to: connecting }
states:
connecting:
after: [ { duration: 10s, transition_to: connecting } ] on_events:
connected: { transition_to: receiving }
receiving:
esvs:
session_bytes: { type: int, init: 0 } on_events:
chunk:
action:
- assign: { session_bytes: "session_bytes + event.payload.bytes" }
- assign: { bytes_done: "bytes_done + event.payload.bytes" }
eof: { transition_to: stored }
stored: { type: final }
- initial: { transition_to: hashing }
states:
hashing:
on_events:
hash_ok: { transition_to: verified }
hash_mismatch: { transition_to: failed } verified: { type: final }
paused:
on_events:
resume: { transition_to: active }
complete:
type: final
entry:
- publish: { event: download_done, to: parent, payload: { id: "id" } }
failed:
entry:
- publish: { event: download_done, to: parent, payload: { id: "id" } }
- stop: {}