summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--internal/daemon.go14
-rw-r--r--internal/lcommon.go38
-rw-r--r--internal/logic.go18
-rw-r--r--internal/ring.go2
5 files changed, 65 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index afc37ad..c86867a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,6 @@ go.work.sum
#logs
logs/
+
+#a4 mess
+tmp/
diff --git a/internal/daemon.go b/internal/daemon.go
index cc202f5..62fdc5c 100644
--- a/internal/daemon.go
+++ b/internal/daemon.go
@@ -10,8 +10,6 @@ import (
"sync"
"sync/atomic"
"time"
-
- "lurchers/internal/api"
)
type Daemon struct {
@@ -28,9 +26,9 @@ func (d *Daemon) HandleConn(ctx context.Context, conn net.Conn) {
scanner := bufio.NewScanner(conn)
for scanner.Scan() {
- var msg api.LurchMsg
+ var msg LurchMsg
- if err := api.Decode(&msg, scanner.Bytes()); err != nil {
+ if err := Decode(&msg, scanner.Bytes()); err != nil {
slog.Error("decode: failed to decode", "error", err)
fmt.Fprintln(conn, "error: invalid json")
continue
@@ -38,7 +36,7 @@ func (d *Daemon) HandleConn(ctx context.Context, conn net.Conn) {
slog.Info("received", "json", msg)
- if err := api.Compute(ctx, &msg, conn); err != nil {
+ if err := Compute(ctx, &msg, conn); err != nil {
slog.Error("parse: failed to parse lurch logic", "error", err)
fmt.Fprintln(conn, "error: failed to parse")
continue
@@ -50,7 +48,8 @@ func (d *Daemon) HandleConn(ctx context.Context, conn net.Conn) {
}
}
-func (d *Daemon) SpawnWorker(ev SysLurchEventT, timeout time.Duration) (uint64, error) {
+// TODO: add in custom command later
+func (d *Daemon) SpawnWorker(ev *SysLurchEventT, timeout time.Duration) (uint64, error) {
offset, slotIdx, err := d.Ring.ClaimSlot()
if err != nil {
return 0, err
@@ -64,7 +63,8 @@ func (d *Daemon) SpawnWorker(ev SysLurchEventT, timeout time.Duration) (uint64,
payloadOffset := offset + SlotHeaderSize
ctx, cancel := context.WithTimeout(d.Ctx, timeout)
- cmd := exec.CommandContext(ctx, "jac", "howler,.py", fmt.Sprintf("%d", payloadOffset))
+ // custom executions; don't know yet with jaclang
+ cmd := exec.CommandContext(ctx, "jac", "howler.jac", fmt.Sprintf("%d", payloadOffset))
// explicit tracking of workers
d.WorkerWg.Add(1)
diff --git a/internal/lcommon.go b/internal/lcommon.go
index f6a846f..e06d310 100644
--- a/internal/lcommon.go
+++ b/internal/lcommon.go
@@ -130,6 +130,7 @@ func WithFileLevel(level slog.Level) func(*options) {
* using the SPSC model
* =======================================================
*/
+
const (
debug bool = false
)
@@ -256,6 +257,43 @@ func Open(filename string) (*ReaderAt, error) {
return r, nil
}
+/*
+ * =======================================================
+ * Lurchers Misc
+ * =======================================================
+ */
+
func unsafePointerAt(data []byte, offset int) unsafe.Pointer {
return unsafe.Pointer(&data[offset])
}
+
+type (
+ workspace int8
+ lurchersIdsTrack map[workspace]int
+)
+
+type idOptions struct {
+ workspace workspace
+}
+
+var id lurchersIdsTrack = map[workspace]int{}
+
+func Id(opts ...func(*idOptions)) int {
+ o := idOptions{
+ workspace: 1,
+ }
+
+ for _, opt := range opts {
+ opt(&o)
+ }
+
+ id[o.workspace] = id[o.workspace] + 1
+
+ return id[o.workspace]
+}
+
+func WithWorkSpace(ws workspace) func(*idOptions) {
+ return func(o *idOptions) {
+ o.workspace = ws
+ }
+}
diff --git a/internal/logic.go b/internal/logic.go
index f6c096f..0174812 100644
--- a/internal/logic.go
+++ b/internal/logic.go
@@ -1,7 +1,9 @@
package internal
import (
+ "errors"
"log/slog"
+ "time"
)
var (
@@ -20,9 +22,21 @@ var (
var (
spawnWorkerArgs lurchArgs = lurchArgs{"timeout_ns": int64(0)}
spawnWorker lurchCallback = func(args lurchArgs) error {
- // tired TODO: finish impl of SpawnWorker from unix api
if dP, ok := args["daemon"].(*Daemon); ok {
- dP.SpawnWorker()
+ if timeout, ok := args["timeout_ns"].(int); ok {
+
+ s, err := dP.SpawnWorker(&SysLurchEventT{EventTime: time.Now().Unix(), EventID: int64(Id())}, time.Duration(timeout))
+ if err != nil {
+ return err
+ }
+
+ slog.Debug("logic: spawnWorker", "claimed ring slot", s)
+ return nil
+ } else {
+ return errors.New("logic: spawnWorker - timeout_ns not in args")
+ }
+ } else {
+ return errors.New("logic: spawnWorker - daemon ptr not in args")
}
}
)
diff --git a/internal/ring.go b/internal/ring.go
index e691949..3cf8ada 100644
--- a/internal/ring.go
+++ b/internal/ring.go
@@ -114,7 +114,7 @@ func (s *SharedRing) InitHeader() {
binary.LittleEndian.PutUint64(s.r.data[16:24], 0)
}
-func (s *SharedRing) WriteHeader(offset int64, ev SysLurchEventT) error {
+func (s *SharedRing) WriteHeader(offset int64, ev *SysLurchEventT) error {
hdr := make([]byte, SlotHeaderSize)
binary.LittleEndian.PutUint64(hdr[0:8], uint64(ev.EventTime))
binary.LittleEndian.PutUint64(hdr[8:16], uint64(ev.EventID))