Skip to content

Commit

Permalink
Fix admin action corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckierDodge committed Sep 11, 2024
1 parent edc7ad1 commit 3f22a72
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/ui/src/components/AdminButtons/CancelButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
main_url: string;
module?: string;
module_status?: string;
wc_state?: any;
}>();
const cancel_url = ref()
Expand Down
9 changes: 9 additions & 0 deletions src/ui/src/components/AdminButtons/LockUnlockButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
const props = defineProps<{
main_url: string;
module?: string;
wc_state?: any;
module_status?: string;
}>();
Expand All @@ -53,8 +54,16 @@
if (props.module_status == 'LOCKED') {
isLocked.value = true
} else {
if (props.wc_state) {
if (props.wc_state.locked) {
isLocked.value = true
} else {
isLocked.value = false
}
} else {
isLocked.value = false
}
}
})
}
Expand Down
12 changes: 11 additions & 1 deletion src/ui/src/components/AdminButtons/PauseResumeButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
</template>

<script lang="ts" setup>
import {defineProps, ref, watchEffect} from 'vue';
import { defineProps, ref, watchEffect } from 'vue';
const props = defineProps<{
main_url: string;
module?: string;
module_status?: string;
wc_state?: any;
}>();
const pause_url = ref()
Expand Down Expand Up @@ -68,6 +69,15 @@
})
}
else {
if (props.wc_state) {
if (props.wc_state.paused) {
isPaused.value = true
} else {
isPaused.value = false
}
} else {
isPaused.value = false
}
allowButton.value = true
}
Expand Down
3 changes: 2 additions & 1 deletion src/ui/src/components/AdminButtons/ResetButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
</template>

<script lang="ts" setup>
import {defineProps, ref, watchEffect} from 'vue';
import { defineProps, ref, watchEffect } from 'vue';
const props = defineProps<{
main_url: string;
module?: string;
module_status?: string;
wc_state?: any;
}>();
const reset_url = ref()
Expand Down
3 changes: 2 additions & 1 deletion src/ui/src/components/AdminButtons/SafetyStopButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
</template>

<script lang="ts" setup>
import {defineProps, ref, watchEffect} from 'vue';
import { defineProps, ref } from 'vue';
const props = defineProps<{
main_url: string;
module?: string;
module_status?: string;
wc_state?: any;
}>();
const safetyStop_url = ref()
Expand Down
3 changes: 2 additions & 1 deletion src/ui/src/components/AdminButtons/ShutdownButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
</template>

<script lang="ts" setup>
import {defineProps, ref, watchEffect} from 'vue';
import { defineProps, ref, watchEffect } from 'vue';
const props = defineProps<{
main_url: string;
module?: string;
module_status?: string;
wc_state?: any;
}>();
const shutdown_url = ref()
Expand Down
12 changes: 6 additions & 6 deletions src/ui/src/components/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<v-card-title class="text-center">
<h2>{{ wc_info.name }}</h2>
<div class="d-flex justify-center">
<PauseResumeButton :main_url="main_url" class="ml-2"/>
<CancelButton :main_url="main_url" class="ml-2" />
<ResetButton :main_url="main_url" class="ml-2" />
<LockUnlockButton :main_url="main_url" class="ml-2"/>
<ShutdownButton :main_url="main_url" class="ml-2" />
<SafetyStopButton :main_url="main_url" class="ml-2"/>
<PauseResumeButton :main_url="main_url" :wc_state=wc_state class="ml-2"/>
<CancelButton :main_url="main_url" :wc_state=wc_state class="ml-2" />
<ResetButton :main_url="main_url" :wc_state=wc_state class="ml-2" />
<LockUnlockButton :main_url="main_url" :wc_state=wc_state class="ml-2"/>
<ShutdownButton :main_url="main_url" :wc_state=wc_state class="ml-2" />
<SafetyStopButton :main_url="main_url" :wc_state=wc_state class="ml-2"/>
</div>
</v-card-title>
<v-card-text>
Expand Down
34 changes: 25 additions & 9 deletions src/wei/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Handles admin commands and related logic."""

from wei.types.interface_types import InterfaceMap
from wei.types.module_types import AdminCommands, Module
from wei.types.module_types import AdminCommands, Module, ModuleStatus
from wei.utils import threaded_task


@threaded_task
def send_safety_stop(module: Module) -> None:
"""Safety stops a module"""
if AdminCommands.SAFETY_STOP in module.about.admin_commands:
if check_can_send_admin_command(module, AdminCommands.SAFETY_STOP):
InterfaceMap.interfaces[module.interface].send_admin_command(
module, AdminCommands.SAFETY_STOP
)
Expand All @@ -16,9 +18,10 @@ def send_safety_stop(module: Module) -> None:
send_pause(module)


@threaded_task
def send_reset(module: Module) -> None:
"""Resets a module"""
if AdminCommands.RESET in module.about.admin_commands:
if check_can_send_admin_command(module, AdminCommands.RESET):
InterfaceMap.interfaces[module.interface].send_admin_command(
module, AdminCommands.RESET
)
Expand All @@ -27,9 +30,10 @@ def send_reset(module: Module) -> None:
print(f"Module {module.name} does not support resetting.")


@threaded_task
def send_pause(module: Module) -> None:
"""Pauses a module"""
if AdminCommands.PAUSE in module.about.admin_commands:
if check_can_send_admin_command(module, AdminCommands.PAUSE):
InterfaceMap.interfaces[module.interface].send_admin_command(
module, AdminCommands.PAUSE
)
Expand All @@ -39,9 +43,10 @@ def send_pause(module: Module) -> None:
send_cancel(module)


@threaded_task
def send_resume(module: Module) -> None:
"""Resumes a module"""
if AdminCommands.RESUME in module.about.admin_commands:
if check_can_send_admin_command(module, AdminCommands.RESUME):
InterfaceMap.interfaces[module.interface].send_admin_command(
module, AdminCommands.RESUME
)
Expand All @@ -50,9 +55,10 @@ def send_resume(module: Module) -> None:
print(f"Module {module.name} does not support resuming.")


@threaded_task
def send_cancel(module: Module) -> None:
"""Cancels a module"""
if AdminCommands.CANCEL in module.about.admin_commands:
if check_can_send_admin_command(module, AdminCommands.CANCEL):
InterfaceMap.interfaces[module.interface].send_admin_command(
module, AdminCommands.CANCEL
)
Expand All @@ -61,9 +67,10 @@ def send_cancel(module: Module) -> None:
print(f"Module {module.name} does not support canceling.")


@threaded_task
def send_shutdown(module: Module) -> None:
"""Shuts down a module"""
if AdminCommands.SHUTDOWN in module.about.admin_commands:
if check_can_send_admin_command(module, AdminCommands.SHUTDOWN):
InterfaceMap.interfaces[module.interface].send_admin_command(
module, AdminCommands.SHUTDOWN
)
Expand All @@ -72,9 +79,10 @@ def send_shutdown(module: Module) -> None:
print(f"Module {module.name} does not support shutting down.")


@threaded_task
def send_lock(module: Module) -> None:
"""Locks a module"""
if AdminCommands.LOCK in module.about.admin_commands:
if check_can_send_admin_command(module, AdminCommands.LOCK):
InterfaceMap.interfaces[module.interface].send_admin_command(
module, AdminCommands.LOCK
)
Expand All @@ -83,12 +91,20 @@ def send_lock(module: Module) -> None:
print(f"Module {module.name} does not support locking.")


@threaded_task
def send_unlock(module: Module) -> None:
"""Unlocks a module"""
if AdminCommands.UNLOCK in module.about.admin_commands:
if check_can_send_admin_command(module, AdminCommands.UNLOCK):
InterfaceMap.interfaces[module.interface].send_admin_command(
module, AdminCommands.UNLOCK
)
print(f"Module {module.name} has been unlocked.")
else:
print(f"Module {module.name} does not support unlocking.")


def check_can_send_admin_command(module: Module, command: AdminCommands) -> bool:
"""Checks if a module can send an admin command"""
return not module.state.status == ModuleStatus.UNKNOWN and (
module.about is None or command in module.about.admin_commands
)
16 changes: 16 additions & 0 deletions src/wei/core/state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ def paused(self, value: bool) -> None:
f"{self._workcell_prefix}:paused", "true" if value else "false"
)

@property
def locked(self) -> bool:
"""Get the lock state of the workcell"""
return self._redis_client.get(f"{self._workcell_prefix}:locked") == "true"

@locked.setter
def locked(self, value: bool) -> None:
"""Set the lock state of the workcell"""
self._redis_client.set(
f"{self._workcell_prefix}:locked", "true" if value else "false"
)

@property
def shutdown(self) -> bool:
"""Get the shutdown state of the workcell"""
Expand Down Expand Up @@ -167,6 +179,9 @@ def get_state(self) -> Dict[str, Dict[Any, Any]]:
"modules": self._modules.to_dict(),
"workflows": self._workflow_runs.to_dict(),
"workcell": self._workcell.to_dict(),
"paused": self.paused,
"locked": self.locked,
"shutdown": self.shutdown,
}

@property
Expand Down Expand Up @@ -207,6 +222,7 @@ def clear_state(
self._workcell.clear()
self.state_change_marker = "0"
self.paused = False
self.locked = False
self.shutdown = False
self.mark_state_changed()

Expand Down

0 comments on commit 3f22a72

Please sign in to comment.