Skip to content

Commit

Permalink
Merge pull request #118 from samply/conflict-resolve
Browse files Browse the repository at this point in the history
Conflict resolve
  • Loading branch information
enola-dkfz authored Feb 26, 2024
2 parents adca7d1 + e1252a8 commit f91fef0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Focus

Focus is a Samply component ran on the sites, which distributes tasks from Beam.Proxy to the applications on the site and re-transmits the results through Samply.Beam. Currenly, only Samply.Blaze is supported as a target application, but Focus is easily extensible.
Focus is a Samply component ran on the sites, which distributes tasks from Beam.Proxy to the applications on the site and re-transmits the results through Samply.Beam.

It is possible to specify the queries whose results are to be cached to speed up retrieval. The cached results expire after 24 hours.
It is possible to specify Blaze queries whose results are to be cached to speed up retrieval. The cached results expire after 24 hours.

## Installation

Expand Down Expand Up @@ -59,7 +59,13 @@ Optionally, you can provide the `TLS_CA_CERTIFICATES_DIR` environment variable t

## Usage

Creating a sample task using CURL:
Creating a sample focus healthcheck task using CURL (body can be any string and is ignored):

```bash
curl -v -X POST -H "Content-Type: application/json" --data '{"id":"7fffefff-ffef-fcff-feef-feffffffffff","from":"app1.proxy1.broker","to":["app1.proxy1.broker"],"ttl":"10s","failure_strategy":{"retry":{"backoff_millisecs":1000,"max_tries":5}},"metadata":{"project":"focus-healthcheck"},"body":"wie geht es"}' -H "Authorization: ApiKey app1.proxy1.broker App1Secret" http://localhost:8081/v1/tasks
```

Creating a sample task containing a Blaze query using CURL:

```bash
curl -v -X POST -H "Content-Type: application/json" --data '{"id":"7fffefff-ffef-fcff-feef-fefbffffeeff","from":"app1.proxy1.broker","to":["app1.proxy1.broker"],"ttl":"10s","failure_strategy":{"retry":{"backoff_millisecs":1000,"max_tries":5}},"metadata":{"project":"exliquid"},"body":"ewoJImxhbmciOiAiY3FsIiwKCSJsaWIiOiB7CgkJImNvbnRlbnQiOiBbCgkJCXsKCQkJCSJjb250ZW50VHlwZSI6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
Expand Down
35 changes: 17 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,31 @@ struct ReportCache {
}

impl ReportCache {

pub fn new() -> Self {
let mut cache = HashMap::new();

if let Some(filename) = CONFIG.queries_to_cache_file_path.clone() {
let lines = util::read_lines(filename.clone().to_string());
match lines {
Ok(ok_lines) => {
for line in ok_lines {
let Ok(ok_line) = line else {
warn!("A line in the file {} is not readable", filename);
continue;
};
cache.insert((ok_line.clone(), false), ("".into(), UNIX_EPOCH));
cache.insert((ok_line, true), ("".into(), UNIX_EPOCH));
}
},
for line in ok_lines {
let Ok(ok_line) = line else {
warn!("A line in the file {} is not readable", filename);
continue;
};
cache.insert((ok_line.clone(), false), ("".into(), UNIX_EPOCH));
cache.insert((ok_line, true), ("".into(), UNIX_EPOCH));
}
}
Err(_) => {
error!("The file {} cannot be opened", filename); //This shouldn't stop focus from running, it's just going to go to blaze every time, but that's not too slow
error!("The file {} cannot be opened", filename); //This shouldn't stop focus from running, it's just going to go to blaze every time, but that's not too slow
}
}
}
Self {cache}

Self { cache }
}
}
}

const REPORTCACHE_TTL: Duration = Duration::from_secs(86400); //24h

Expand Down Expand Up @@ -133,7 +132,7 @@ async fn main_loop() -> ExitCode {

if let Err(e) = process_tasks(&mut task_queue, &mut seen_tasks).await {
warn!("Encountered the following error, while processing tasks: {e}");
failures += 1;
failures += 1;
} else {
failures = 0;
}
Expand All @@ -150,7 +149,6 @@ async fn process_tasks(
seen: &mut HashSet<MsgId>,
) -> Result<(), FocusError> {
debug!("Start processing tasks...");

let tasks = beam::retrieve_tasks().await?;
for task in tasks {
if seen.contains(&task.id) {
Expand Down Expand Up @@ -182,7 +180,8 @@ async fn run_cql_query(

let mut key_exists = false;

let obfuscate = CONFIG.obfuscate == config::Obfuscate::Yes && !CONFIG.unobfuscated.contains(&project);
let obfuscate =
CONFIG.obfuscate == config::Obfuscate::Yes && !CONFIG.unobfuscated.contains(&project);

let report_from_cache = match report_cache
.lock()
Expand Down

0 comments on commit f91fef0

Please sign in to comment.