aboutsummaryrefslogtreecommitdiff
path: root/bus.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bus.go48
1 files changed, 48 insertions, 0 deletions
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
+}