fetch_ml/native/rust/queue_index/include/queue_index.h
Jeremie Fraeys 7efefa1933
feat(native): implement Rust native layer as a test
- queue_index: mmap-based priority queue with safe storage wrapper
- dataset_hash: BLAKE3 parallel hashing with rayon
- common: FFI utilities with panic recovery
- Minimal deps: ~20 total (rayon, blake3, memmap2, walkdir, chrono)
- Drop crossbeam, prometheus - use stdlib + manual metrics
- Makefile: cargo build targets, help text updated
- Forgejo CI: clippy, tests, miri, cargo-deny
- C FFI compatible with existing Go bindings
2026-03-14 17:45:58 -04:00

49 lines
1.4 KiB
C

#ifndef QUEUE_INDEX_H
#define QUEUE_INDEX_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
// Opaque handle for queue index
typedef struct qi_index qi_index_t;
// Task structure - matches Go queue.Task fields
// Fixed-size for binary format (no dynamic allocation in hot path)
typedef struct qi_task {
char id[64]; // Task ID
char job_name[128]; // Job name
int64_t priority; // Higher = more important
int64_t created_at; // Unix timestamp (nanoseconds)
int64_t next_retry; // Unix timestamp (nanoseconds), 0 if none
char status[16]; // "queued", "running", "finished", "failed"
uint32_t retries; // Current retry count
} qi_task_t;
// Index operations
qi_index_t* qi_open(const char* queue_dir);
void qi_close(qi_index_t* idx);
// Batch operations (amortize CGo overhead)
int qi_add_tasks(qi_index_t* idx, const qi_task_t* tasks, uint32_t count);
int qi_get_next_batch(qi_index_t* idx, qi_task_t* out_tasks, uint32_t max_count, uint32_t* out_count);
// Query operations
int qi_get_task_by_id(qi_index_t* idx, const char* task_id, qi_task_t* out_task);
size_t qi_get_task_count(qi_index_t* idx, const char* status);
// Memory management
void qi_free_task_array(qi_task_t* tasks);
// Error handling
const char* qi_last_error(qi_index_t* idx);
void qi_clear_error(qi_index_t* idx);
#ifdef __cplusplus
}
#endif
#endif // QUEUE_INDEX_H