From 641a95063946bf7f4b8fdd1e938a917bc3f75cb2 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Thu, 5 Feb 2026 14:35:00 +0300 Subject: initial --- bus.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 bus.go (limited to 'bus.go') diff --git a/bus.go b/bus.go new file mode 100644 index 0000000..d491113 --- /dev/null +++ b/bus.go @@ -0,0 +1,48 @@ +package fqueue + +import ( + "errors" + "os" + "path/filepath" + "time" +) + +const ( + seqFile = "_seq.txt" + queueDir = "queue" + processingDir = "processing" + + // Максимальное время сколько задача может находиться в статусе + // «обрабатывается» самой шиной. При этом не учитывается время на обработку + // задачи пользовательским кодом, а только с момента как *шина* + // заблокировала задачу и до момента её передачи из NextTask. + // Умозрительно считаю, что секунда это даже много. + maxProcessTime = time.Second +) + +var ( + ErrCantGetExLock = errors.New("cant get exclusive lock") +) + +type Bus struct { + queuePath string + processingPath string + seqFile string +} + +func New(path string) (*Bus, error) { + queuePath := filepath.Join(path, queueDir) + processingPath := filepath.Join(path, processingDir) + if err := os.MkdirAll(queuePath, 0o700); err != nil { + return nil, err + } + if err := os.MkdirAll(processingPath, 0o700); err != nil { + return nil, err + } + + return &Bus{ + queuePath: queuePath, + processingPath: processingPath, + seqFile: filepath.Join(path, seqFile), + }, nil +} -- cgit v1.2.3