filed
Job queue using FUSE
git clone git://mccd.space/filed
| Log | Files | Refs | README | LICENSE |
commit 6b46d57c98d799442fcd138a5a58596b5064a5c3 parent f45a9a53e03cefb6c24493d4e12f9ea86070bd18 Author: Marc Coquand <marc@coquand.email> Date: Sun, 14 Dec 2025 14:50:36 +0100 Inode gen Diffstat:
| M | store/store.go | | | 14 | ++++++++++++-- |
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/store/store.go b/store/store.go
@@ -20,6 +20,7 @@ const (
type Job struct {
ID string
State string
+ INode int
Command string
// Command output on completion
Output []byte
@@ -56,6 +57,7 @@ func (s *Store) initSchema() error {
query := `
CREATE TABLE IF NOT EXISTS jobs (
id TEXT PRIMARY KEY,
+ inode INTEGER,
state TEXT NOT NULL,
command TEXT NOT NULL,
output BLOB,
@@ -63,6 +65,14 @@ func (s *Store) initSchema() error {
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
+ CREATE TRIGGER IF NOT EXISTS auto_increment_inode_trigger
+ AFTER INSERT ON jobs
+ WHEN new.inode IS NULL
+ BEGIN
+ UPDATE jobs
+ SET inode = (SELECT IFNULL(MAX(inode), 0) + 1 FROM jobs)
+ WHERE id = new.id;
+ END;
CREATE INDEX IF NOT EXISTS idx_state ON jobs(state);
`
@@ -98,10 +108,10 @@ func (s *Store) CreateJob(id string, command string) (*Job, error) {
}
func (s *Store) GetJob(id string) (*Job, error) {
- query := `SELECT id, state, command, output, attempts, created_at FROM jobs WHERE id = ?`
+ query := `SELECT id, state, inode, command, output, attempts, created_at FROM jobs WHERE id = ?`
j := &Job{}
err := s.db.QueryRow(query, id).Scan(
- &j.ID, &j.State, &j.Command, &j.Output, &j.Attempts, &j.CreatedAt,
+ &j.ID, &j.State, &j.INode, &j.Command, &j.Output, &j.Attempts, &j.CreatedAt,
)
if err == sql.ErrNoRows {
return nil, os.ErrNotExist