Skip to content

Commit

Permalink
Merge pull request #20 from jhnnsrs/moving-to-lok-next
Browse files Browse the repository at this point in the history
Moving to lok next
  • Loading branch information
jhnnsrs authored Feb 12, 2024
2 parents 3b1c967 + d0538b0 commit 159c9e6
Show file tree
Hide file tree
Showing 66 changed files with 1,940 additions and 444 deletions.
1 change: 0 additions & 1 deletion contrib/fakts

This file was deleted.

1 change: 0 additions & 1 deletion contrib/herre

This file was deleted.

6 changes: 6 additions & 0 deletions graphql/kluster/mutations/dask_cluster.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ mutation CreateNewCluster($name: String!){
createDaskCluster(input: {name: $name}){
...DaskCluster
}
}

mutation ScaleDaskCluster($id: ID!, $n: Int!){
scaleDaskCluster(input: {id: $id, nWorkers: $n}){
...DaskCluster
}
}
16 changes: 16 additions & 0 deletions graphql/omero-ark/fragments/dataset.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fragment ListDataset on Dataset {
id
name
description
}


fragment Dataset on Dataset {
id
name
description
images {
...ListImage
}
tags
}
13 changes: 13 additions & 0 deletions graphql/omero-ark/fragments/image.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fragment ListImage on Image {
id
name
description
}


fragment Image on Image {
id
name
acquisitionDate
tags
}
16 changes: 16 additions & 0 deletions graphql/omero-ark/fragments/project.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fragment ListProject on Project {
id
name
description
}


fragment Project on Project {
id
name
description
datasets {
...ListDataset
}
tags
}
6 changes: 6 additions & 0 deletions graphql/omero-ark/mutations/dataset.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mutation CreateDataset($name: String!, $description: String, $projectId: ID!) {
createDataset(input: {name: $name, description: $description, projectId: $projectId}) {
id
name
}
}
5 changes: 5 additions & 0 deletions graphql/omero-ark/mutations/image.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation DeleteImage($id: ID!) {
deleteImage(input: {id: $id}) {
id
}
}
6 changes: 6 additions & 0 deletions graphql/omero-ark/mutations/project.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mutation CreateProject($name: String!, $description: String) {
createProject(input: {name: $name, description: $description}) {
id
name
}
}
19 changes: 19 additions & 0 deletions graphql/omero-ark/mutations/user.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mutation EnsureOmeroUser($username: String!, $password: String!, $host: String, $port: Int) {
ensureOmeroUser(input: {username: $username, password: $password, host: $host, port: $port}) {
id
omeroUsername
omeroPassword
user {
id
sub
}
}

}

mutation DeleteMe {
deleteMe {
id
sub
}
}
11 changes: 11 additions & 0 deletions graphql/omero-ark/queries/dataset.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query ListDatasets {
datasets {
...ListDataset
}
}

query GetDataset($id: ID!) {
dataset(id: $id) {
...Dataset
}
}
12 changes: 12 additions & 0 deletions graphql/omero-ark/queries/image.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
query ListImages {
images {
...ListImage
}
}


query GetImage($id: ID!) {
image(id: $id) {
...Image
}
}
8 changes: 8 additions & 0 deletions graphql/omero-ark/queries/me.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query Me {
me {
omeroUser {
id
omeroUsername
}
}
}
13 changes: 13 additions & 0 deletions graphql/omero-ark/queries/project.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query ListProjects {
projects {
...ListProject
}
}


query GetProject($id: ID!) {
project(id: $id) {
...Project
}
}

2 changes: 2 additions & 0 deletions graphql/rekuest/fragments/reservation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fragment DetailReservation on Reservation {
kind
name
scope
hash
description
args {
__typename
Expand Down Expand Up @@ -140,6 +141,7 @@ fragment ListReservation on Reservation {
id
kind
name
hash
description
args {
__typename
Expand Down
20 changes: 20 additions & 0 deletions omero_ark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
overwrite: true
schema: "http://localhost:8888/graphql"
documents: "graphql/omero-ark/**/*.graphql"
generates:
src/omero-ark/api/fragments.ts:
plugins:
- "fragment-matcher"
src/omero-ark/api/graphql.ts:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
config:
withHooks: true
reactApolloVersion: 3
arrayInputCoercion: false

src/omero-ark/graphql.schema.json:
plugins:
- "introspection"
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"mikro_next": "graphql-codegen --config mikro_next.yml",
"herre": "graphql-codegen --config herre.yml",
"kluster": "graphql-codegen --config kluster.yml",
"omero": "graphql-codegen --config omero_ark.yml",
"lok": "graphql-codegen --config lok.yml",
"dockbuild": "vite build && docker build -t jhnnsrs/orkestrator:release .",
"paperbuild": "vite build && docker build -t jhnnsrs/orkestrator:paper .",
Expand All @@ -30,7 +31,7 @@
"@headlessui/react": "^1.5.0",
"@heroicons/react": "^1.0.6",
"@jhnnsrs/datalayer": "0.0.7",
"@jhnnsrs/fakts": "^0.0.17",
"@jhnnsrs/fakts": "^0.0.25",
"@jhnnsrs/herre": "0.0.11",
"@jhnnsrs/kluster": "^0.0.1",
"@jhnnsrs/omero-ark": "^0.0.1",
Expand Down
101 changes: 100 additions & 1 deletion src-tauri/src/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use httparse;
use httparse::Request;
use std::future::{poll_fn, IntoFuture};
use std::io::Cursor;
use std::{
borrow::Cow,
Expand All @@ -15,8 +16,14 @@ use tauri::{
Runtime,
};
use tauri::{utils::config::AppUrl, window::WindowBuilder, WindowUrl};
use tokio::net::UdpSocket;

use tokio::time::{sleep, Duration};
use std::sync::{Arc, Mutex};
use tokio::task::JoinHandle;
use crate::SharedState;
use std::future::Future;
use tokio::net::UdpSocket;
use tokio::time::timeout;

type DownloadResult<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
const EXIT: [u8; 4] = [1, 3, 3, 7];
Expand All @@ -33,8 +40,31 @@ pub struct OauthConfig {
///
/// Default: `"<html><body>Please return to the app.</body></html>"`.
pub response: Option<Cow<'static, str>>,

}


#[derive(Default, serde::Deserialize)]
pub struct FaktsConfig {
/// An array of hard-coded ports the server should try to bind to.
/// This should only be used if your oauth provider does not accept wildcard localhost addresses.
///
/// Default: Asks the system for a free port.
pub port: Option<u16>,
/// Optional static html string send to the user after being redirected.
/// Keep it self-contained and as small as possible.
///
/// Default: `"<html><body>Please return to the app.</body></html>"`
pub magic_word: Option<Cow<'static, str>>,
pub wait_duration: Option<u64>
}

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
pub struct Beacon {
pub url: String,
}


/// Starts the localhost (using 127.0.0.1) server. Returns the port its listening on.
///
/// Because of the unprotected localhost port, you _must_ verify the URL in the handler function.
Expand Down Expand Up @@ -187,6 +217,7 @@ pub fn cancel_listen(port: u16) -> Result<(), std::io::Error> {
#[tauri::command]
pub fn oauth_start(app: tauri::AppHandle, config: Option<OauthConfig>) -> Result<u16, String> {
let config = config.unwrap_or_default();


start_with_config(config, move |url| match url::Url::parse(&url) {
Ok(_) => {
Expand Down Expand Up @@ -220,6 +251,74 @@ pub fn oauth_cancel(port: u16) -> Result<(), String> {
cancel_listen(port).map_err(|err| err.to_string())
}





#[tauri::command]
pub async fn fakts_start(app: tauri::AppHandle, state: tauri::State<'_, SharedState>, config: Option<FaktsConfig>) -> Result<Vec<Beacon>, String> {
let config = config.unwrap_or_default();

// Bind to the UDP socket
let socket = match UdpSocket::bind("0.0.0.0:45678").await {
Ok(s) => s,
Err(e) => return Err(format!("couldn't bind socket: {}", e)),
};

let mut buf = [0u8; 1500];
let mut beacons = Vec::new();

let duration = Duration::from_secs(config.wait_duration.unwrap_or(10));
let start_time = tokio::time::Instant::now();

loop {
// Check if the specified duration has elapsed
if start_time.elapsed() >= duration {
break;
}

// Calculate the remaining time to listen
let remaining_time = duration - start_time.elapsed();

// Wait for data with a timeout based on the remaining time
match timeout(remaining_time, socket.recv_from(&mut buf)).await {
Ok(Ok((amt, _src))) => {
let data = &buf[..amt];
if let Ok(s) = std::str::from_utf8(data) {
if s.starts_with("beacon-fakts") {
if let Ok(x) = serde_json::from_str::<Beacon>(s.strip_prefix("beacon-fakts").unwrap()) {
beacons.push(x);
}
}
}
}
// Handle timeout or other errors
Err(_) | Ok(Err(_)) => break,
}
}

println!("Done collecting beacons");
Ok(beacons)


}

#[tauri::command]
pub async fn fakts_cancel( state: tauri::State<'_, SharedState>) -> Result<String, String> {
let mut handle_storage = state.task_handle.lock().unwrap();
if let Some(handle) = handle_storage.take() {
handle.abort(); // This will attempt to cancel the task
return Ok("Cancelled".to_string());
}
*handle_storage = None;


Ok("Nothing to cancel".to_string())
}




#[tauri::command]
pub async fn upload_file(
file: std::path::PathBuf,
Expand Down
Loading

0 comments on commit 159c9e6

Please sign in to comment.