diff options
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 +} |
