Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/fluxqueue-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fluxqueue_core"
version = "0.2.1"
version = "0.3.0-rc1"
repository.workspace = true
homepage.workspace = true
authors.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/fluxqueue-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl FluxQueueCore {

#[pymodule]
fn _core(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
m.add_class::<FluxQueueCore>()?;
Ok(())
}
2 changes: 1 addition & 1 deletion crates/fluxqueue-worker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fluxqueue-worker"
version = "0.2.1"
version = "0.3.0-rc1"
edition = "2024"

[lib]
Expand Down
56 changes: 55 additions & 1 deletion crates/fluxqueue-worker/src/worker.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anyhow::Result;
use anyhow::{Result, anyhow};
use pyo3::Python;
use pyo3::types::PyAnyMethods;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;
Expand All @@ -18,6 +20,11 @@ pub async fn run_worker(
queue_name: String,
save_dead_tasks: bool,
) -> Result<()> {
check_client_library_version().map_err(|e| {
tracing::error!("{}", e);
std::process::exit(1);
})?;

let redis_client = RedisClient::new(&redis_url).await.map_err(|e| {
tracing::error!("{}", e);
std::process::exit(1);
Expand Down Expand Up @@ -331,6 +338,53 @@ fn check_worker_is_ready(ready_check: ReadyCheck) {
}
}

fn check_client_library_version() -> Result<()> {
let worker_version = env!("CARGO_PKG_VERSION");
let library_version = Python::attach(|py| -> Result<String> {
let module = py.import("fluxqueue")?;
let version = module.getattr("__version__")?;
Ok(version.to_string())
})?;

let comparison = compare_versions(worker_version, &library_version);
if comparison == -1 {
tracing::warn!(
"Worker version '{}' is older than client library '{}'. For full functionality, update the worker to match the client version.",
worker_version,
&library_version
);
}

if comparison == 1 {
return Err(anyhow!(
"Minimum required client library version is: {}, found: {}",
worker_version,
&library_version
));
}

Ok(())
}

fn compare_versions(v1: &str, v2: &str) -> i8 {
let mut parts1: Vec<u32> = v1.split('.').map(|p| p.parse().unwrap_or(0)).collect();
let mut parts2: Vec<u32> = v2.split('.').map(|p| p.parse().unwrap_or(0)).collect();

let len = parts1.len().max(parts2.len());
parts1.resize(len, 0);
parts2.resize(len, 0);

for (a, b) in parts1.iter().zip(parts2.iter()) {
if a > b {
return 1;
}
if a < b {
return -1;
}
}
0
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions python/fluxqueue/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ._core import __version__ as __version__
from .client import FluxQueue as FluxQueue
from .context import Context as Context
from .models import TaskMetadata as TaskMetadata