filed
Job queue using FUSE
git clone git://mccd.space/filed
| Log | Files | Refs | README | LICENSE |
commit 4d71c9004e063a8779f42ab72eb3eb92f15a3538 parent 137b406e800fecdcefd851bbc6f0f4f105bbd632 Author: Marc Coquand <marc@coquand.email> Date: Sat, 13 Dec 2025 17:27:05 +0100 Cleanup Diffstat:
| M | store/store.go | | | 7 | ++----- |
| M | store/store_test.go | | | 12 | ++++-------- |
2 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/store/store.go b/store/store.go
@@ -95,8 +95,6 @@ func (s *Store) CreateJob(id string, command string) (*Job, error) {
return j, nil
}
-// GetJob retrieves a job by ID.
-// Used by FUSE Read/GetAttr operations.
func (s *Store) GetJob(id string) (*Job, error) {
query := `SELECT id, state, command, output, attempts, created_at FROM jobs WHERE id = ?`
j := &Job{}
@@ -109,7 +107,6 @@ func (s *Store) GetJob(id string) (*Job, error) {
return j, err
}
-// DeleteJob removes a job.
func (s *Store) DeleteJob(id string) error {
res, err := s.db.Exec("DELETE FROM jobs WHERE id = ?", id)
if err != nil {
@@ -186,8 +183,8 @@ func (s *Store) RestartJob(id string) error {
return nil
}
-func (s *Store) CompleteJob(id string) error {
- _, err := s.db.Exec("UPDATE jobs SET state = ?, updated_at = ? WHERE id = ?", StateCompleted, time.Now(), id)
+func (s *Store) CompleteJob(id string, output string) error {
+ _, err := s.db.Exec("UPDATE jobs SET state = ?, output = ?, updated_at = ? WHERE id = ?", StateCompleted, output, time.Now(), id)
return err
}
diff --git a/store/store_test.go b/store/store_test.go
@@ -5,10 +5,9 @@ import (
"testing"
)
-// setupTestDB creates a new store in a temporary directory for each test.
+// Create a new store in a temporary directory for each test.
func setupTestDB(t *testing.T) *Store {
t.Helper()
- // Create a temporary directory that is automatically cleaned up
tmpDir := t.TempDir()
dbPath := filepath.Join(tmpDir, "jobs.db")
@@ -17,7 +16,6 @@ func setupTestDB(t *testing.T) *Store {
t.Fatalf("Failed to create store: %v", err)
}
- // Ensure we close the store after the test finishes
t.Cleanup(func() {
store.Close()
})
@@ -31,7 +29,6 @@ func TestCreateJob(t *testing.T) {
jobID := "job-123"
cmd := "echo hello"
- // Test Creation
job, err := s.CreateJob(jobID, cmd)
if err != nil {
t.Fatalf("Failed to create job: %v", err)
@@ -72,7 +69,7 @@ func TestLifecycleTransitions(t *testing.T) {
s := setupTestDB(t)
jobID := "lifecycle-1"
- _, err := s.CreateJob(jobID, "ffmpeg -i ...")
+ _, err := s.CreateJob(jobID, "echo hello")
if err != nil {
t.Fatalf("CreateJob failed: %v", err)
}
@@ -91,7 +88,7 @@ func TestLifecycleTransitions(t *testing.T) {
}
// 2. Running -> Completed
- if err := s.CompleteJob(jobID); err != nil {
+ if err := s.CompleteJob(jobID, "hello"); err != nil {
t.Fatalf("CompleteJob failed: %v", err)
}
@@ -114,12 +111,11 @@ func TestLifecycleTransitions(t *testing.T) {
func TestListJobsByState(t *testing.T) {
s := setupTestDB(t)
- // Create 2 pending jobs and 1 completed job
s.CreateJob("p1", "cmd1")
s.CreateJob("p2", "cmd2")
s.CreateJob("c1", "cmd3")
- s.CompleteJob("c1")
+ s.CompleteJob("c1", "out")
// List Pending
pending, err := s.ListJobsByState(StatePending)