Skip to content

Commit

Permalink
Update releated parts to fit updated types
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev committed Dec 15, 2024
1 parent b6af726 commit 6140ba9
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 122 deletions.
8 changes: 4 additions & 4 deletions application/apps/indexer/session/src/handlers/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ pub async fn handle(
operation_api: &OperationAPI,
ms: u64,
ignore_cancellation: bool,
) -> OperationResult<stypes::SleepResult> {
) -> OperationResult<stypes::ResultSleep> {
if ignore_cancellation {
time::sleep(time::Duration::from_millis(ms)).await;
Ok(Some(stypes::SleepResult { sleep_well: true }))
Ok(Some(stypes::ResultSleep { sleep_well: true }))
} else {
let canceler = operation_api.cancellation_token();
select! {
_ = async move {
time::sleep(time::Duration::from_millis(ms)).await;
} => {
Ok(Some( stypes::SleepResult { sleep_well: true }))
Ok(Some( stypes::ResultSleep { sleep_well: true }))
},
_ = canceler.cancelled() => {
Ok(Some( stypes::SleepResult { sleep_well: false }))
Ok(Some( stypes::ResultSleep { sleep_well: false }))
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions application/apps/indexer/session/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ impl std::fmt::Display for OperationKind {
#[derive(Debug, Serialize, Clone)]
pub struct NoOperationResults;

pub type OperationResult<T>
where
T: Serialize,
= Result<Option<T>, stypes::NativeError>;
pub type OperationResult<T> = Result<Option<T>, stypes::NativeError>;

#[derive(Clone)]
pub struct OperationAPI {
Expand Down
4 changes: 2 additions & 2 deletions application/apps/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ gen_encode_decode_fns!(ExtractedMatchValue);
gen_encode_decode_fns!(ResultExtractedMatchValues);
gen_encode_decode_fns!(ResultU64);
gen_encode_decode_fns!(ResultBool);
gen_encode_decode_fns!(SleepResult);
gen_encode_decode_fns!(ResultSleep);
gen_encode_decode_fns!(NearestPosition);
gen_encode_decode_fns!(ResultNearestPosition);
gen_encode_decode_fns!(CandlePoint);
gen_encode_decode_fns!(Point);
gen_encode_decode_fns!(ResultSearchValues);
gen_encode_decode_fns!(ResultScaledDistribution);
1 change: 1 addition & 0 deletions application/apps/rustcore/rs-bindings/Cargo.lock

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

14 changes: 7 additions & 7 deletions application/apps/rustcore/rs-bindings/src/js/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ impl RustSession {
options: JSArrayBuffer,
operation_id: String,
) -> Result<(), stypes::ComputationError> {
let options = stypes::ObserveOptions::decode(&options.to_vec())
.map_err(stypes::ComputationError::Decoding)?;
let options =
stypes::ObserveOptions::decode(&options).map_err(stypes::ComputationError::Decoding)?;
self.session
.as_ref()
.ok_or(stypes::ComputationError::SessionUnavailable)?
Expand Down Expand Up @@ -576,8 +576,8 @@ impl RustSession {
target: String,
request: JSArrayBuffer,
) -> Result<stypes::SdeResponse, stypes::ComputationError> {
let request = stypes::SdeRequest::decode(&request.to_vec())
.map_err(stypes::ComputationError::Decoding)?;
let request =
stypes::SdeRequest::decode(&request).map_err(stypes::ComputationError::Decoding)?;
let session = self
.session
.as_ref()
Expand Down Expand Up @@ -622,7 +622,7 @@ impl RustSession {
stypes::ComputationError::NativeError(e),
)
})?;
Ok(stypes::Ranges(ranges))
Ok(ranges.into())
}

#[node_bindgen]
Expand All @@ -633,7 +633,7 @@ impl RustSession {
.state
.set_debug(debug)
.await
.map_err(|e: stypes::NativeError| stypes::ComputationError::NativeError(e).into())
.map_err(|e: stypes::NativeError| stypes::ComputationError::NativeError(e))
}

#[node_bindgen]
Expand All @@ -644,7 +644,7 @@ impl RustSession {
.tracker
.get_operations_stat()
.await
.map_err(|e: stypes::NativeError| stypes::ComputationError::NativeError(e).into())
.map_err(|e: stypes::NativeError| stypes::ComputationError::NativeError(e))
}

#[node_bindgen]
Expand Down
204 changes: 107 additions & 97 deletions application/apps/rustcore/ts-bindings/spec/session.values.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,114 +17,124 @@ const MAX_DATASET_LEN = 65000;
describe('Values', function () {
it(config.regular.list[1], function () {
return runners.withSession(config.regular, 1, async (logger, done, comps) => {
let sum = 0;
const tmpobj = createSampleFile(5000, logger, (i: number) => {
if (i % 100 === 0 || i <= 5) {
sum += i;
return `[${i}]:: some data CPU=${i}% line data\n`;
} else {
return `[${i}]:: some line data\n`;
}
});
comps.stream
.observe(
new Factory.File()
.asText()
.type(Factory.FileType.Text)
.file(tmpobj.name)
.get()
.sterilized(),
)
.on('processing', () => {
comps.search.values([`CPU=(\\d{1,})`]).catch(finish.bind(null, comps.session, done));
let sum = 0;
const tmpobj = createSampleFile(5000, logger, (i: number) => {
if (i % 100 === 0 || i <= 5) {
sum += i;
return `[${i}]:: some data CPU=${i}% line data\n`;
} else {
return `[${i}]:: some line data\n`;
}
});
comps.stream
.observe(
new Factory.File()
.asText()
.type(Factory.FileType.Text)
.file(tmpobj.name)
.get()
.sterilized(),
)
.on('processing', () => {
comps.search
.values([`CPU=(\\d{1,})`])
.catch(finish.bind(null, comps.session, done));
})
.catch(finish.bind(null, comps.session, done));
comps.events.SearchValuesUpdated.subscribe((map) => {
if (map === null) {
// Before get results rustcore should inform FE about dropping results.
return;
}
comps.search
.getValues(MAX_DATASET_LEN)
.then((data) => {
let control = 0;
data.forEach((point) => {
point[1].forEach((p) => {
control += p.y_value;
});
});
expect(control).toEqual(sum);
finish(comps.session, done);
})
.catch(finish.bind(null, comps.session, done));
comps.events.SearchValuesUpdated.subscribe((map) => {
if (map === null) {
// Before get results rustcore should inform FE about dropping results.
return;
}
});
});
});
it(config.regular.list[2], function () {
return runners.withSession(config.regular, 2, async (logger, done, comps) => {
let sum = 0;
const tmpobj = createSampleFile(5000, logger, (i: number) => {
if (i % 100 === 0 || i <= 5) {
sum += i;
return `[${i}]:: some data CPU=${i}% line data\n`;
} else {
return `[${i}]:: some line data\n`;
}
});
let iteration = 0;
comps.stream
.observe(
new Factory.File()
.asText()
.type(Factory.FileType.Text)
.file(tmpobj.name)
.get()
.sterilized(),
)
.on('processing', () => {
comps.search
.values([`CPU=(\\d{1,})`])
.catch(finish.bind(null, comps.session, done));
})
.catch(finish.bind(null, comps.session, done));
comps.events.SearchValuesUpdated.subscribe((map) => {
if (map === null) {
// Before get results rustcore should inform FE about dropping results.
return;
}
if (iteration === 0) {
comps.search
.getValues(MAX_DATASET_LEN)
.then((data) => {
let control = 0;
data[0].forEach((pair) => {
control += pair[3];
data.forEach((point) => {
point[1].forEach((p) => {
control += p.y_value;
});
});
expect(control).toEqual(sum);
finish(comps.session, done);
const offset = 5000;
appendToSampleFile(tmpobj, 5000, logger, (i: number) => {
if (i % 100 === 0 || i <= 5) {
sum += i + offset;
return `[${i}]:: some data CPU=${i + offset}% line data\n`;
} else {
return `[${i}]:: some line data\n`;
}
});
})
.catch(finish.bind(null, comps.session, done));
});
});
});
it(config.regular.list[2], function () {
return runners.withSession(config.regular, 2, async (logger, done, comps) => {
let sum = 0;
const tmpobj = createSampleFile(5000, logger, (i: number) => {
if (i % 100 === 0 || i <= 5) {
sum += i;
return `[${i}]:: some data CPU=${i}% line data\n`;
} else {
return `[${i}]:: some line data\n`;
}
});
let iteration = 0;
comps.stream
.observe(
new Factory.File()
.asText()
.type(Factory.FileType.Text)
.file(tmpobj.name)
.get()
.sterilized(),
)
.on('processing', () => {
comps.search.values([`CPU=(\\d{1,})`]).catch(finish.bind(null, comps.session, done));
})
.catch(finish.bind(null, comps.session, done));
comps.events.SearchValuesUpdated.subscribe((map) => {
if (map === null) {
// Before get results rustcore should inform FE about dropping results.
return;
}
if (iteration === 0) {
comps.search
.getValues(MAX_DATASET_LEN)
.then((data) => {
let control = 0;
data[0].forEach((pair) => {
control += pair[3];
});
expect(control).toEqual(sum);
const offset = 5000;
appendToSampleFile(tmpobj, 5000, logger, (i: number) => {
if (i % 100 === 0 || i <= 5) {
sum += i + offset;
return `[${i}]:: some data CPU=${i + offset}% line data\n`;
} else {
return `[${i}]:: some line data\n`;
}
});
})
.catch(finish.bind(null, comps.session, done));
iteration += 1;
} else if (iteration === 1) {
comps.search
.getValues(MAX_DATASET_LEN)
.then((data) => {
let control = 0;
data[0].forEach((pair) => {
control += pair[3];
iteration += 1;
} else if (iteration === 1) {
comps.search
.getValues(MAX_DATASET_LEN)
.then((data) => {
let control = 0;
data.forEach((point) => {
point[1].forEach((p) => {
control += p.y_value;
});
expect(control).toEqual(sum);
finish(comps.session, done);
})
.catch(finish.bind(null, comps.session, done));
} else {
expect(iteration).toEqual(1);
}
});
});
expect(control).toEqual(sum);
finish(comps.session, done);
})
.catch(finish.bind(null, comps.session, done));
} else {
expect(iteration).toEqual(1);
}
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const executor: TExecutor<ISleepResults, IExecuteSleepOptions> = (
reject: (err: Error) => void,
) {
try {
const result: ISleepResults = protocol.decodeSleepResult(data);
const result: ISleepResults = protocol.decodeResultSleep(data);
resolve(result);
} catch (e) {
return reject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const executor: TExecutor<boolean, Options> = (
resolve: (done: boolean) => void,
reject: (err: Error) => void,
) {
const result = protocol.decodeResultBool(data);
const result: boolean = protocol.decodeResultBool(data);
if (typeof result !== 'boolean') {
return reject(
new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const executor: TExecutor<boolean, Options> = (
resolve: (done: boolean) => void,
reject: (err: Error) => void,
) {
const result = protocol.decodeResultBool(data);
const result: boolean = protocol.decodeResultBool(data);
if (typeof result !== 'boolean') {
return reject(
new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const executor: TExecutor<TExtractedValues, IFilter[]> = (
reject: (err: Error) => void,
) {
try {
const src: TExtractedValuesSrc = protocol.decodeExtractedMatchValueList(data);
const src: TExtractedValuesSrc = protocol.decodeResultExtractedMatchValues(data);
if (!(src instanceof Array)) {
return reject(
new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const executor: TExecutor<IValuesMap, IOptions> = (
},
function (data: Uint8Array, resolve: (r: IValuesMap) => void, reject: (e: Error) => void) {
try {
const map = protocol.decodeResultSearchValues(data);
resolve(data as IValuesMap);
const map: IValuesMap = protocol.decodeResultSearchValues(data);
resolve(map as IValuesMap);
} catch (e) {
reject(new Error(error(e)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const executor: TExecutor<number, IFilter[]> = (
resolve: (found: number) => void,
reject: (err: Error) => void,
) {
const found = protocol.decodeResultU64(data);
const found: number = protocol.decodeResultU64(data);
if (typeof found !== 'number' || isNaN(found) || !isFinite(found)) {
return reject(
new Error(
Expand Down
9 changes: 8 additions & 1 deletion application/platform/types/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ export enum EFlag {

export type ISearchMap = Array<[number, number][]>;

export type IValuesMap = Map<number, [number, number, number, number][]>;
export interface Point {
row: number;
min: number;
max: number;
y_value: number;
}

export type IValuesMap = [number, Point[]][];

export type IValuesMinMaxMap = { [key: number]: [number, number] };

Expand Down

0 comments on commit 6140ba9

Please sign in to comment.