mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-23 15:17:57 +01:00
Do not do raw processing on restores
This commit is contained in:
parent
98ed9efec9
commit
386ac5645d
@ -34,6 +34,67 @@ impl Process {
|
|||||||
I: IntoIterator<Item = S>,
|
I: IntoIterator<Item = S>,
|
||||||
S: AsRef<std::ffi::OsStr>,
|
S: AsRef<std::ffi::OsStr>,
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Actor for Process {
|
||||||
|
fn restore(&mut self, state: ArchivedValue<State>) -> BoxFuture<'static, ()> {
|
||||||
|
tracing::debug!(name=%self.name, cmd=%self.cmd, ?state,
|
||||||
|
"Process actor updating state");
|
||||||
|
let mut command = Command::new(&self.cmd);
|
||||||
|
command
|
||||||
|
.stdin(Stdio::null())
|
||||||
|
.args(self.args.iter())
|
||||||
|
.arg(&self.name);
|
||||||
|
|
||||||
|
match &state.as_ref().inner.state {
|
||||||
|
ArchivedStatus::Free => {
|
||||||
|
command.arg("free");
|
||||||
|
}
|
||||||
|
ArchivedStatus::InUse(by) => {
|
||||||
|
command.arg("inuse").arg(by.id.as_str());
|
||||||
|
}
|
||||||
|
ArchivedStatus::ToCheck(by) => {
|
||||||
|
command.arg("tocheck").arg(by.id.as_str());
|
||||||
|
}
|
||||||
|
ArchivedStatus::Blocked(by) => {
|
||||||
|
command.arg("blocked").arg(by.id.as_str());
|
||||||
|
}
|
||||||
|
ArchivedStatus::Disabled => {
|
||||||
|
command.arg("disabled");
|
||||||
|
}
|
||||||
|
ArchivedStatus::Reserved(by) => {
|
||||||
|
command.arg("reserved").arg(by.id.as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let name = self.name.clone();
|
||||||
|
Box::pin(async move {
|
||||||
|
match command.output() {
|
||||||
|
Ok(retv) if retv.status.success() => {
|
||||||
|
tracing::trace!("Actor was restored");
|
||||||
|
let outstr = String::from_utf8_lossy(&retv.stdout);
|
||||||
|
for line in outstr.lines() {
|
||||||
|
tracing::debug!(%name, %line, "actor stdout");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(retv) => {
|
||||||
|
tracing::warn!(%name, ?state, code=?retv.status,
|
||||||
|
"Actor failed to restore: nonzero exitcode"
|
||||||
|
);
|
||||||
|
if !retv.stderr.is_empty() {
|
||||||
|
let errstr = String::from_utf8_lossy(&retv.stderr);
|
||||||
|
for line in errstr.lines() {
|
||||||
|
tracing::warn!(%name, %line, "actor stderr");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(error) => tracing::warn!(%name, ?error, "process actor failed to run cmd"),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply(&mut self, state: ArchivedValue<State>) -> BoxFuture<'static, ()> {
|
||||||
tracing::debug!(name=%self.name, cmd=%self.cmd, ?state,
|
tracing::debug!(name=%self.name, cmd=%self.cmd, ?state,
|
||||||
"Process actor updating state");
|
"Process actor updating state");
|
||||||
let mut command = Command::new(&self.cmd);
|
let mut command = Command::new(&self.cmd);
|
||||||
@ -68,42 +129,6 @@ impl Process {
|
|||||||
command.arg("raw").arg(b64);
|
command.arg("raw").arg(b64);
|
||||||
}
|
}
|
||||||
|
|
||||||
command
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Actor for Process {
|
|
||||||
fn restore(&mut self, state: ArchivedValue<State>) -> BoxFuture<'static, ()> {
|
|
||||||
let mut command = self.build_command(&state, ["--restore"]);
|
|
||||||
let name = self.name.clone();
|
|
||||||
Box::pin(async move {
|
|
||||||
match command.output() {
|
|
||||||
Ok(retv) if retv.status.success() => {
|
|
||||||
tracing::trace!("Actor was restored");
|
|
||||||
let outstr = String::from_utf8_lossy(&retv.stdout);
|
|
||||||
for line in outstr.lines() {
|
|
||||||
tracing::debug!(%name, %line, "actor stdout");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(retv) => {
|
|
||||||
tracing::warn!(%name, ?state, code=?retv.status,
|
|
||||||
"Actor failed to restore: nonzero exitcode"
|
|
||||||
);
|
|
||||||
if !retv.stderr.is_empty() {
|
|
||||||
let errstr = String::from_utf8_lossy(&retv.stderr);
|
|
||||||
for line in errstr.lines() {
|
|
||||||
tracing::warn!(%name, %line, "actor stderr");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(error) => tracing::warn!(%name, ?error, "process actor failed to run cmd"),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn apply(&mut self, state: ArchivedValue<State>) -> BoxFuture<'static, ()> {
|
|
||||||
let empty: [&str; 0] = [];
|
|
||||||
let mut command = self.build_command(&state, empty);
|
|
||||||
let name = self.name.clone();
|
let name = self.name.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
match command.output() {
|
match command.output() {
|
||||||
|
@ -129,6 +129,9 @@ def main(args):
|
|||||||
else:
|
else:
|
||||||
args.verbose = 0
|
args.verbose = 0
|
||||||
|
|
||||||
|
if args.restore and args.verbose > 0:
|
||||||
|
print("running in restore mode")
|
||||||
|
|
||||||
# You could also check the actor name here and call different functions
|
# You could also check the actor name here and call different functions
|
||||||
# depending on that variable instead of passing it to the state change
|
# depending on that variable instead of passing it to the state change
|
||||||
# methods.
|
# methods.
|
||||||
@ -160,6 +163,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
parser.add_argument("-q", "--quiet", help="be less verbose", action="store_true")
|
parser.add_argument("-q", "--quiet", help="be less verbose", action="store_true")
|
||||||
parser.add_argument("-v", "--verbose", help="be more verbose", action="count")
|
parser.add_argument("-v", "--verbose", help="be more verbose", action="count")
|
||||||
|
parser.add_argument("-r", "--restore", help="run in restore mode", action="store_true")
|
||||||
|
|
||||||
parser.add_argument("name",
|
parser.add_argument("name",
|
||||||
help="name of this actor as configured in bffh.dhall"
|
help="name of this actor as configured in bffh.dhall"
|
||||||
|
Loading…
Reference in New Issue
Block a user