Skip to content

Commit

Permalink
WIP: add lock/unlock support; testing
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckierDodge committed Sep 11, 2024
1 parent ea77ecd commit 8a063d6
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 217 deletions.
12 changes: 11 additions & 1 deletion pdm.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies = [
'uvicorn[standard]>=0.21',
"websockets>=12.0",
"secure-smtplib>=0.1.1",
"aenum>=3.1.15",
]

[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is @generated by PDM.
# Please do not edit it manually.

aenum==3.1.15
annotated-types==0.7.0
anyio==4.4.0
asttokens==2.4.1
Expand Down Expand Up @@ -67,7 +68,6 @@ types-urllib3==1.26.25.14
typing-extensions==4.12.2
ulid-py==1.1.0
urllib3==1.26.19
uvicorn==0.30.6
uvicorn[standard]==0.30.6
uvloop==0.20.0; (sys_platform != "cygwin" and sys_platform != "win32") and platform_python_implementation != "PyPy"
virtualenv==20.26.3
Expand Down
2 changes: 1 addition & 1 deletion requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is @generated by PDM.
# Please do not edit it manually.

aenum==3.1.15
alabaster==0.7.13
annotated-types==0.7.0
anyio==4.4.0
Expand Down Expand Up @@ -54,7 +55,6 @@ starlette==0.38.2
typing-extensions==4.12.2
ulid-py==1.1.0
urllib3==1.26.19
uvicorn==0.30.6
uvicorn[standard]==0.30.6
uvloop==0.20.0; (sys_platform != "cygwin" and sys_platform != "win32") and platform_python_implementation != "PyPy"
watchfiles==0.23.0
Expand Down
4 changes: 1 addition & 3 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is @generated by PDM.
# Please do not edit it manually.

aenum==3.1.15
alabaster==0.7.13
annotated-types==0.7.0
anyio==4.4.0
Expand All @@ -17,7 +18,6 @@ click==8.1.7
colorama==0.4.6; sys_platform == "win32" or os_name == "nt" or platform_system == "Windows"
cryptography==43.0.0
devtools==0.12.2
diaspora-event-sdk==0.3.2
diaspora-event-sdk[kafka-python]==0.3.2
distlib==0.3.8
docutils==0.20.1
Expand Down Expand Up @@ -51,7 +51,6 @@ pydantic==2.8.2
pydantic-core==2.20.1
pydantic-settings==2.4.0
pygments==2.18.0
pyjwt==2.9.0
pyjwt[crypto]==2.9.0
pyproject-hooks==1.1.0
pytest==8.3.2
Expand Down Expand Up @@ -94,7 +93,6 @@ types-urllib3==1.26.25.14
typing-extensions==4.12.2
ulid-py==1.1.0
urllib3==1.26.19
uvicorn==0.30.6
uvicorn[standard]==0.30.6
uvloop==0.20.0; (sys_platform != "cygwin" and sys_platform != "win32") and platform_python_implementation != "PyPy"
virtualenv==20.26.3
Expand Down
75 changes: 38 additions & 37 deletions src/ui/src/components/AdminButtons/LockUnlockButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</template>

<script lang="ts" setup>
import {defineProps, ref, watchEffect} from 'vue';
import { defineProps, ref, watchEffect } from 'vue';
const props = defineProps<{
main_url: string;
Expand All @@ -37,18 +37,19 @@
// Format pause and resume urls
if (props.module) {
// TODO: Module lock and unlock urls
lock_url.value = props.main_url.concat('/admin/lock/'.concat(props.module))
unlock_url.value = props.main_url.concat('/admin/unlock/'.concat(props.module))
hoverText.value = "Module"
}
else {
// TODO: Workcell lock and unlock urls
lock_url.value = props.main_url.concat('/admin/lock')
unlock_url.value = props.main_url.concat('/admin/unlock')
hoverText.value = "Workcell"
}
if (props.module) {
watchEffect(() => {
// Determine if the module is already locked
// TODO: Implement 'LOCKED' status
if (props.module_status == 'LOCKED') {
isLocked.value = true
} else {
Expand All @@ -59,45 +60,45 @@
// Function to toggle lock/unlock
const toggleLockUnlock = async () => {
// if (isLocked.value) {
// await sendUnlockCommand();
// } else {
// await sendLockCommand();
// }
if (isLocked.value) {
await sendUnlockCommand();
} else {
await sendLockCommand();
}
isLocked.value = !isLocked.value;
};
// // Function to send lock command
// const sendLockCommand = async () => {
// try {
// const response = await fetch(lock_url.value, {
// method: 'POST',
// });
// if (!response.ok) {
// throw new Error(`HTTP error! status: ${response.status}`);
// }
// console.log('Locked');
// Function to send lock command
const sendLockCommand = async () => {
try {
const response = await fetch(lock_url.value, {
method: 'POST',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
console.log('Locked');
// } catch (error) {
// console.error('Error locking:', error);
// }
// };
} catch (error) {
console.error('Error locking:', error);
}
};
// // Function to send unlock command
// const sendUnlockCommand = async () => {
// try {
// const response = await fetch(unlock_url.value, {
// method: 'POST',
// });
// Function to send unlock command
const sendUnlockCommand = async () => {
try {
const response = await fetch(unlock_url.value, {
method: 'POST',
});
// if (!response.ok) {
// throw new Error(`HTTP error! status: ${response.status}`);
// }
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
// console.log('Unlocked');
console.log('Unlocked');
// } catch (error) {
// console.error('Error unlocking:', error);
// }
// };
} catch (error) {
console.error('Error unlocking:', error);
}
};
</script>
59 changes: 29 additions & 30 deletions src/ui/src/components/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@
import { ref, watchEffect } from 'vue';
import VueJsonPretty from 'vue-json-pretty';
import 'vue-json-pretty/lib/styles.css';
import CancelButton from './AdminButtons/CancelButton.vue';
import LockUnlockButton from './AdminButtons/LockUnlockButton.vue';
import PauseResumeButton from './AdminButtons/PauseResumeButton.vue';
import ResetButton from './AdminButtons/ResetButton.vue';
import SafetyStopButton from './AdminButtons/SafetyStopButton.vue';
import LockUnlockButton from './AdminButtons/LockUnlockButton.vue';
import ShutdownButton from './AdminButtons/ShutdownButton.vue';
import CancelButton from './AdminButtons/CancelButton.vue';
import ResetButton from './AdminButtons/ResetButton.vue';
const main_url = ref()
const state_url = ref()
const workcell_info_url = ref()
Expand Down Expand Up @@ -181,62 +181,61 @@ export default {
padding: 3px;
}
.module_status_IDLE {
.wf_status_completed,
.module_status_IDLE,
.module_status_READY {
background-color: green;
}
.wf_status_running,
.module_status_BUSY {
background-color: blue;
}
.wf_status_failed,
.module_status_ERROR {
background-color: red;
}
.wf_status_unknown,
.module_status_UNKNOWN {
background-color: darkgrey;
color: black;
background-color: darkslategray;
}
.wf_status_new,
.module_status_INIT {
background-color: purple;
}
.module_status_PAUSED {
background-color: gold;
background-color: aquamarine;
color: black;
}
.wf_indicator {
width: 10px;
height: 10px;
border-radius: 5px;
margin-left: 10px;
}
.wf_status_queued,
.wf_status_new,
.wf_status_paused {
.wf_status_paused,
.wf_status_in_progress,
.module_status_PAUSED {
background-color: gold;
color: black;
}
.wf_status_running,
.wf_status_in_progress {
background-color: blue;
background-color: darkblue;
color: black;
}
.wf_status_completed {
background-color: green;
.module_status_LOCKED {
background-color: darkgoldenrod;
color: white;
}
.wf_status_failed,
.wf_status_cancelled {
background-color: red;
.wf_status_cancelled,
.module_status_CANCELLED {
background-color: darkorange;
color: black;
}
.wf_status_unknown {
background-color: darkgray;
.wf_indicator {
width: 10px;
height: 10px;
border-radius: 5px;
margin-left: 10px;
}
</style>
22 changes: 22 additions & 0 deletions src/wei/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,25 @@ def send_shutdown(module: Module) -> None:
print(f"Module {module.name} has been shut down.")
else:
print(f"Module {module.name} does not support shutting down.")


def send_lock(module: Module) -> None:
"""Locks a module"""
if AdminCommands.LOCK in module.about.admin_commands:
InterfaceMap.interfaces[module.interface].send_admin_command(
module, AdminCommands.LOCK
)
print(f"Module {module.name} has been locked.")
else:
print(f"Module {module.name} does not support locking.")


def send_unlock(module: Module) -> None:
"""Unlocks a module"""
if AdminCommands.UNLOCK in module.about.admin_commands:
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.")
2 changes: 1 addition & 1 deletion src/wei/core/interfaces/simulate_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def send_action(step: Step, module: Module, **kwargs: Any) -> Tuple[str, str, st
@staticmethod
def get_state(module: Module, **kwargs: Any) -> Dict[str, Any]:
"""Returns the current state of the module"""
return {"State": ModuleStatus.IDLE}
return {"State": ModuleStatus.READY}
2 changes: 1 addition & 1 deletion src/wei/core/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def check_step(experiment_id: str, run_id: str, step: Step) -> bool:
print(f"Can't run {run_id}.{step.name}, source is reserved")
return False
module = state_manager.get_module(step.module)
if module.state.status != ModuleStatus.IDLE:
if ModuleStatus(module.state.status) != ModuleStatus.READY:
print(
f"Can't run '{run_id}.{step.name}', module '{step.module}' is not idle. Module status: {module.state.status}"
)
Expand Down
Loading

0 comments on commit 8a063d6

Please sign in to comment.