Rewrite state machines

This commit is contained in:
Ben Sarmiento
2024-05-21 17:07:40 +02:00
parent 6c24d74f61
commit 0743b01223
12 changed files with 69 additions and 55 deletions

View File

@@ -5,36 +5,30 @@ import (
)
func NewTorrentState(initial string) *fsm.FSM {
// ok
// broken
// under_repair
// deleted
// unplayable
// ok_torrent 1
// broken_torrent 1
// unplayable_torrent 1
return fsm.NewFSM(
initial,
fsm.Events{
{Name: "break", Src: []string{"ok", "unplayable"}, Dst: "broken"},
{Name: "repair", Src: []string{"broken"}, Dst: "under_repair"},
{Name: "repair_done", Src: []string{"under_repair"}, Dst: "ok"},
{Name: "delete", Src: []string{"ok", "broken", "under_repair", "unplayable"}, Dst: "deleted"},
{Name: "mark_as_unplayable", Src: []string{"ok", "under_repair"}, Dst: "unplayable"},
{Name: "break_torrent", Src: []string{"ok_torrent", "unplayable_torrent"}, Dst: "broken_torrent"},
{Name: "repair_torrent", Src: []string{"broken_torrent"}, Dst: "ok_torrent"},
{Name: "mark_as_unplayable_torrent", Src: []string{"ok_torrent"}, Dst: "unplayable_torrent"},
},
fsm.Callbacks{},
)
}
func NewFileState(initial string) *fsm.FSM {
// ok
// broken
// under_repair
// deleted
// ok_file 13
// broken_file 5
// deleted_file 3
return fsm.NewFSM(
initial,
fsm.Events{
{Name: "break", Src: []string{"ok"}, Dst: "broken"},
{Name: "repair", Src: []string{"broken"}, Dst: "under_repair"},
{Name: "repair_done", Src: []string{"under_repair"}, Dst: "ok"},
{Name: "delete", Src: []string{"ok", "broken", "under_repair"}, Dst: "deleted"},
{Name: "break_file", Src: []string{"ok_file"}, Dst: "broken_file"},
{Name: "repair_file", Src: []string{"broken_file"}, Dst: "ok_file"},
{Name: "delete_file", Src: []string{"ok_file", "broken_file"}, Dst: "deleted_file"},
},
fsm.Callbacks{},
)