itsi-scheduler 0.1.5 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of itsi-scheduler might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75599726844e215e80b59ae8a95549e23024e4e070d768ca3f085a8fbb2591a9
4
- data.tar.gz: c84726c45c08562ad4b8ebd4a6c9eb4ebd1f50521afca027c1e6a69d8b2e4eb5
3
+ metadata.gz: '06169b51c9344ad3892f08cf099c459f9bea7377d7e7b3342a54b9314e7f0c8f'
4
+ data.tar.gz: d18702aac863d7bf49c100cbcd0be525031d8ed7f334368d507c9ffee53abcbd
5
5
  SHA512:
6
- metadata.gz: 0a944a2d952111520bf473853ec7b363ed16a53ddf4b0ae252c0fab36d70b4dedb561d55feab827d34c21b0d468cb6b0e978dba22584bc873092cc3d9515a7af
7
- data.tar.gz: 5e27924c41ebc8f6b84f8d1e507ff04d3d86d8326c2da21ca2cbe4b1fc703b7bd0026813cf8353775e126d562e25cae93ed8c03f714b07eb48c4d3e15b91fc94
6
+ metadata.gz: 54a585ef25065bcf8e038a87d80a214a1a17aac9f5510a083d6598928d48c879866d89723c399473faf8ef96f8464a5c2b0b3f3d0d24cdc551e11aae9574b9fe
7
+ data.tar.gz: 3c102f1994d0c6beee8473261fe49a206addcd04f80afdc09a0eaf8ebf6d31f738cbfbc4afa00dff0d9790a65fa426e0bd7e34c4e7f341231a9b4c036bc0583d
data/Cargo.lock CHANGED
@@ -68,9 +68,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
68
68
 
69
69
  [[package]]
70
70
  name = "cc"
71
- version = "1.2.16"
71
+ version = "1.2.15"
72
72
  source = "registry+https://github.com/rust-lang/crates.io-index"
73
- checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c"
73
+ checksum = "c736e259eea577f443d5c86c304f9f4ae0295c43f3ba05c21f1d66b5f06001af"
74
74
  dependencies = [
75
75
  "shlex",
76
76
  ]
@@ -186,9 +186,9 @@ dependencies = [
186
186
 
187
187
  [[package]]
188
188
  name = "itoa"
189
- version = "1.0.15"
189
+ version = "1.0.14"
190
190
  source = "registry+https://github.com/rust-lang/crates.io-index"
191
- checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
191
+ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
192
192
 
193
193
  [[package]]
194
194
  name = "itsi-scheduler"
@@ -507,9 +507,9 @@ dependencies = [
507
507
 
508
508
  [[package]]
509
509
  name = "redox_syscall"
510
- version = "0.5.10"
510
+ version = "0.5.9"
511
511
  source = "registry+https://github.com/rust-lang/crates.io-index"
512
- checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1"
512
+ checksum = "82b568323e98e49e2a0899dcee453dd679fae22d69adf9b11dd508d1549b7e2f"
513
513
  dependencies = [
514
514
  "bitflags",
515
515
  ]
@@ -560,9 +560,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
560
560
 
561
561
  [[package]]
562
562
  name = "ring"
563
- version = "0.17.11"
563
+ version = "0.17.14"
564
564
  source = "registry+https://github.com/rust-lang/crates.io-index"
565
- checksum = "da5349ae27d3887ca812fb375b45a4fbb36d8d12d2df394968cd86e35683fe73"
565
+ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
566
566
  dependencies = [
567
567
  "cc",
568
568
  "cfg-if",
@@ -586,9 +586,9 @@ checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c"
586
586
 
587
587
  [[package]]
588
588
  name = "ryu"
589
- version = "1.0.20"
589
+ version = "1.0.19"
590
590
  source = "registry+https://github.com/rust-lang/crates.io-index"
591
- checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
591
+ checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd"
592
592
 
593
593
  [[package]]
594
594
  name = "scopeguard"
@@ -624,9 +624,9 @@ dependencies = [
624
624
 
625
625
  [[package]]
626
626
  name = "serde_json"
627
- version = "1.0.140"
627
+ version = "1.0.139"
628
628
  source = "registry+https://github.com/rust-lang/crates.io-index"
629
- checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
629
+ checksum = "44f86c3acccc9c65b153fe1b85a3be07fe5515274ec9f0653b4a0875731c72a6"
630
630
  dependencies = [
631
631
  "itoa",
632
632
  "memchr",
@@ -1,5 +1,12 @@
1
+ use magnus::{
2
+ Error,
3
+ error::ErrorType,
4
+ exception::{self, arg_error, exception},
5
+ };
6
+ use nix::errno::Errno;
7
+
1
8
  use crate::ItsiError;
2
- use std::ffi::NulError;
9
+ use std::{ffi::NulError, io};
3
10
 
4
11
  pub static CLIENT_CONNECTION_CLOSED: &str = "Client disconnected";
5
12
 
@@ -9,14 +16,14 @@ impl From<httparse::Error> for ItsiError {
9
16
  }
10
17
  }
11
18
 
12
- impl From<nix::errno::Errno> for ItsiError {
13
- fn from(err: nix::errno::Errno) -> Self {
19
+ impl From<Errno> for ItsiError {
20
+ fn from(err: Errno) -> Self {
14
21
  ItsiError::ArgumentError(err.to_string())
15
22
  }
16
23
  }
17
24
 
18
- impl From<std::io::Error> for ItsiError {
19
- fn from(err: std::io::Error) -> Self {
25
+ impl From<io::Error> for ItsiError {
26
+ fn from(err: io::Error) -> Self {
20
27
  ItsiError::ArgumentError(err.to_string())
21
28
  }
22
29
  }
@@ -33,39 +40,29 @@ impl From<NulError> for ItsiError {
33
40
  }
34
41
  }
35
42
 
36
- impl From<magnus::Error> for ItsiError {
37
- fn from(err: magnus::Error) -> Self {
43
+ impl From<Error> for ItsiError {
44
+ fn from(err: Error) -> Self {
38
45
  match err.error_type() {
39
- magnus::error::ErrorType::Jump(tag) => ItsiError::Jump(tag.to_string()),
40
- magnus::error::ErrorType::Error(_exception_class, cow) => {
41
- ItsiError::ArgumentError(cow.to_string())
42
- }
43
- magnus::error::ErrorType::Exception(exception) => {
44
- ItsiError::ArgumentError(exception.to_string())
45
- }
46
+ ErrorType::Jump(tag) => ItsiError::Jump(tag.to_string()),
47
+ ErrorType::Error(_exception_class, cow) => ItsiError::ArgumentError(cow.to_string()),
48
+ ErrorType::Exception(exception) => ItsiError::ArgumentError(exception.to_string()),
46
49
  }
47
50
  }
48
51
  }
49
52
 
50
- impl From<ItsiError> for magnus::Error {
53
+ impl From<ItsiError> for Error {
51
54
  fn from(err: ItsiError) -> Self {
52
55
  match err {
53
- ItsiError::InvalidInput(msg) => magnus::Error::new(magnus::exception::arg_error(), msg),
54
- ItsiError::InternalServerError(msg) => {
55
- magnus::Error::new(magnus::exception::exception(), msg)
56
- }
57
- ItsiError::UnsupportedProtocol(msg) => {
58
- magnus::Error::new(magnus::exception::arg_error(), msg)
59
- }
60
- ItsiError::ArgumentError(msg) => {
61
- magnus::Error::new(magnus::exception::arg_error(), msg)
62
- }
63
- ItsiError::Jump(msg) => magnus::Error::new(magnus::exception::local_jump_error(), msg),
64
- ItsiError::Break() => magnus::Error::new(magnus::exception::interrupt(), "Break"),
56
+ ItsiError::InvalidInput(msg) => Error::new(arg_error(), msg),
57
+ ItsiError::InternalServerError(msg) => Error::new(exception(), msg),
58
+ ItsiError::UnsupportedProtocol(msg) => Error::new(arg_error(), msg),
59
+ ItsiError::ArgumentError(msg) => Error::new(arg_error(), msg),
60
+ ItsiError::Jump(msg) => Error::new(exception::local_jump_error(), msg),
61
+ ItsiError::Break() => Error::new(exception::interrupt(), "Break"),
65
62
  ItsiError::ClientConnectionClosed => {
66
- magnus::Error::new(magnus::exception::eof_error(), CLIENT_CONNECTION_CLOSED)
63
+ Error::new(exception::eof_error(), CLIENT_CONNECTION_CLOSED)
67
64
  }
68
- ItsiError::Pass() => magnus::Error::new(magnus::exception::interrupt(), "Pass"),
65
+ ItsiError::Pass() => Error::new(exception::interrupt(), "Pass"),
69
66
  }
70
67
  }
71
68
  }
@@ -3,7 +3,7 @@ use thiserror::Error;
3
3
 
4
4
  pub type Result<T> = std::result::Result<T, ItsiError>;
5
5
 
6
- #[derive(Error, Debug)]
6
+ #[derive(Error, Debug, Clone)]
7
7
  pub enum ItsiError {
8
8
  #[error("Invalid input {0}")]
9
9
  InvalidInput(String),
@@ -1,7 +1,8 @@
1
- use std::{os::raw::c_void, ptr::null_mut, sync::Arc};
1
+ use std::{os::raw::c_void, ptr::null_mut};
2
2
 
3
3
  use magnus::{
4
4
  RArray, Ruby, Thread, Value,
5
+ block::Proc,
5
6
  rb_sys::FromRawValue,
6
7
  value::{LazyId, ReprValue},
7
8
  };
@@ -17,6 +18,7 @@ static ID_LIST: LazyId = LazyId::new("list");
17
18
  static ID_EQ: LazyId = LazyId::new("==");
18
19
  static ID_ALIVE: LazyId = LazyId::new("alive?");
19
20
  static ID_THREAD_VARIABLE_GET: LazyId = LazyId::new("thread_variable_get");
21
+ static ID_BACKTRACE: LazyId = LazyId::new("backtrace");
20
22
 
21
23
  pub fn schedule_thread() {
22
24
  unsafe {
@@ -120,20 +122,30 @@ where
120
122
  *result_box
121
123
  }
122
124
 
123
- pub fn fork(after_fork: Arc<Option<impl Fn()>>) -> Option<i32> {
125
+ pub fn fork(after_fork: Option<HeapValue<Proc>>) -> Option<i32> {
124
126
  let ruby = Ruby::get().unwrap();
125
127
  let fork_result = ruby
126
128
  .module_kernel()
127
129
  .funcall::<_, _, Option<i32>>(*ID_FORK, ())
128
130
  .unwrap();
129
131
  if fork_result.is_none() {
130
- if let Some(f) = &*after_fork {
131
- f()
132
+ if let Some(proc) = after_fork {
133
+ call_proc_and_log_errors(proc)
132
134
  }
133
135
  }
134
136
  fork_result
135
137
  }
136
138
 
139
+ pub fn call_proc_and_log_errors(proc: HeapValue<Proc>) {
140
+ if let Err(e) = proc.call::<_, Value>(()) {
141
+ if let Some(value) = e.value() {
142
+ print_rb_backtrace(value);
143
+ } else {
144
+ eprintln!("Error occurred {:?}", e);
145
+ }
146
+ }
147
+ }
148
+
137
149
  pub fn kill_threads<T>(threads: Vec<T>)
138
150
  where
139
151
  T: ReprValue,
@@ -176,3 +188,14 @@ pub fn terminate_non_fork_safe_threads() {
176
188
 
177
189
  kill_threads(non_fork_safe_threads);
178
190
  }
191
+
192
+ pub fn print_rb_backtrace(rb_err: Value) {
193
+ let backtrace = rb_err
194
+ .funcall::<_, _, Vec<String>>(*ID_BACKTRACE, ())
195
+ .unwrap_or_default();
196
+
197
+ eprintln!("Ruby exception {:?}", rb_err);
198
+ for line in backtrace {
199
+ eprintln!("{}", line);
200
+ }
201
+ }