-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add processes endpoint #30
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
72c3e92
Add processes endpoint
NinadBhat 59af654
add tests
NinadBhat b73823c
Add post process
NinadBhat 08ae34a
Add importlib
NinadBhat 1935184
Suggested changes
NinadBhat ed55964
Suggested changes
NinadBhat 4e477fb
Add tests
NinadBhat cd33bb2
move to uuid
NinadBhat 10a39f8
Merge branch 'master' into processes
NinadBhat 9861649
change importlib version
NinadBhat 1dfa072
change aiida-version
NinadBhat e2f7c35
Merge branch 'master' into processes
NinadBhat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||
# -*- coding: utf-8 -*- | ||||||
"""Declaration of FastAPI application.""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
from typing import List, Optional | ||||||
|
||||||
from aiida import orm | ||||||
from aiida.cmdline.utils.decorators import with_dbenv | ||||||
from aiida.orm.querybuilder import QueryBuilder | ||||||
from fastapi import APIRouter | ||||||
|
||||||
from aiida_restapi.models import Process | ||||||
|
||||||
router = APIRouter() | ||||||
|
||||||
|
||||||
@router.get("/processes", response_model=List[Process]) | ||||||
@with_dbenv() | ||||||
async def read_processes() -> List[Process]: | ||||||
"""Get list of all processes""" | ||||||
|
||||||
return Process.get_entities() | ||||||
|
||||||
|
||||||
@router.get("/processes/projectable_properties", response_model=List[str]) | ||||||
async def get_processes_projectable_properties() -> List[str]: | ||||||
"""Get projectable properties for processes endpoint""" | ||||||
|
||||||
return Process.get_projectable_properties() | ||||||
|
||||||
|
||||||
@router.get("/processes/{proc_id}", response_model=Process) | ||||||
@with_dbenv() | ||||||
async def read_process(proc_id: int) -> Optional[Process]: | ||||||
"""Get process by id.""" | ||||||
qbobj = QueryBuilder() | ||||||
qbobj.append( | ||||||
orm.ProcessNode, filters={"id": proc_id}, project=["**"], tag="process" | ||||||
).limit(1) | ||||||
|
||||||
return qbobj.dict()[0]["process"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,8 @@ | |||||
"""pytest fixtures for simplified testing.""" | ||||||
import pytest | ||||||
from aiida import orm | ||||||
from aiida.engine import ProcessState | ||||||
from aiida.orm import WorkChainNode, WorkFunctionNode | ||||||
from fastapi.testclient import TestClient | ||||||
|
||||||
from aiida_restapi import app, config | ||||||
|
@@ -53,6 +55,44 @@ def default_computers(): | |||||
return [comp_1.id, comp_2.id] | ||||||
|
||||||
|
||||||
@pytest.fixture(scope="function") | ||||||
def default_process(): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"""Populate database with some process""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
calcs = [] | ||||||
process_label = "SomeDummyWorkFunctionNode" | ||||||
|
||||||
# Create 6 WorkFunctionNodes and WorkChainNodes (one for each ProcessState) | ||||||
for state in ProcessState: | ||||||
|
||||||
calc = WorkFunctionNode() | ||||||
calc.set_process_state(state) | ||||||
|
||||||
# Set the WorkFunctionNode as successful | ||||||
if state == ProcessState.FINISHED: | ||||||
calc.set_exit_status(0) | ||||||
|
||||||
# Give a `process_label` to the `WorkFunctionNodes` so the `--process-label` option can be tested | ||||||
calc.set_attribute("process_label", process_label) | ||||||
|
||||||
calc.store() | ||||||
calcs.append(calc.id) | ||||||
|
||||||
calc = WorkChainNode() | ||||||
calc.set_process_state(state) | ||||||
|
||||||
# Set the WorkChainNode as failed | ||||||
if state == ProcessState.FINISHED: | ||||||
calc.set_exit_status(1) | ||||||
|
||||||
# Set the waiting work chain as paused as well | ||||||
if state == ProcessState.WAITING: | ||||||
calc.pause() | ||||||
|
||||||
calc.store() | ||||||
calcs.append(calc.id) | ||||||
return calcs | ||||||
|
||||||
|
||||||
@pytest.fixture(scope="function") | ||||||
def default_groups(): | ||||||
"""Populate database with some groups.""" | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
data: | ||
aiidaVersion: 1.6.3 | ||
aiidaVersion: 1.6.4 | ||
node: | ||
label: node 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UUID stands for "universally unique identifier", i.e. "unique" is already part of the abbreviation