diff options
| author | 2026-02-05 14:35:00 +0300 | |
|---|---|---|
| committer | 2026-02-05 14:35:00 +0300 | |
| commit | 641a95063946bf7f4b8fdd1e938a917bc3f75cb2 (patch) | |
| tree | d19a6b92845de37e66b57b305fbcaf9f4816ffe9 /bus.go | |
| download | fqueue-master.tar.gz fqueue-master.tar.bz2 fqueue-master.tar.xz fqueue-master.zip | |
Diffstat (limited to '')
| -rw-r--r-- | bus.go | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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 +} |
