-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat/monitor data status #83
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM sagebionetworks/synapsepythonclient:v4.2.0 | ||
|
||
WORKDIR /app | ||
|
||
COPY update_data_status.py /app/update_data_status.py | ||
|
||
ENTRYPOINT ["python3", "/app/update_data_status.py"] | ||
|
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,28 @@ | ||
## Monitor Data Status | ||
|
||
This is a scheduled job that checks "Data Pending" projects for their first file contribution to change project data status to "Under Embargo". | ||
Files may not be immediately annotated with upload; therefore, see also "monitor annotations", which is concerned with annotations on files. | ||
This job is intended to be run on service catalog. | ||
|
||
### Secrets and env vars | ||
|
||
- `SYNAPSE_AUTH_TOKEN`: (Required) This needs to have edit access to update the projects' annotations. | ||
|
||
|
||
### Run params | ||
|
||
- `--dry` By default, the job updates project in Synapse unless `--dry` is used for the run. | ||
- `--update_df` Use a csv to that directly specifies which projects should be updated, instead of querying the project view + file view. This is used for testing. Should have columns `projectId`, and `N`. | ||
|
||
|
||
### Testing | ||
|
||
- Build the image with e.g. `docker build --no-cache -t ghcr.io/nf-osi/jobs-monitor-data-status .` (or pull current/pre-build image if available) | ||
- Set up an `envfile-monitor-ds` with contents like below: | ||
|
||
``` | ||
SCHEDULED_JOB_SECRETS={"SYNAPSE_AUTH_TOKEN":"xxxxxxxxxxxxxxxxxxxxxxxxxxxx"} | ||
``` | ||
|
||
- To run with `--dry`: `docker run --env-file envfile-monitor-ds ghcr.io/nf-osi/jobs-monitor-data-status --dry` | ||
- To run without `--dry` but with test data: `sudo docker run --env-file envfile-monitor-ds --mount type=bind,source=$(pwd)/test.csv,target=/app/test.csv ghcr.io/nf-osi/jobs-monitor-data-status --update_df test.csv` |
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,3 @@ | ||
projectId,N | ||
syn22410511,5 | ||
syn26462036,10 |
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,52 @@ | ||
import synapseclient | ||
import pandas as pd | ||
import os | ||
import json | ||
import argparse | ||
|
||
# Constants for the views | ||
FILE_VIEW_ID = "syn16858331" | ||
PROJECT_VIEW_ID = "syn52677631" | ||
|
||
def main(dry_run, update_df): | ||
syn = synapseclient.Synapse() | ||
secrets = json.loads(os.getenv("SCHEDULED_JOB_SECRETS")) | ||
auth_token = secrets["SYNAPSE_AUTH_TOKEN"] | ||
syn.login(authToken = auth_token) | ||
|
||
if update_df: | ||
print(f"Using manually specified data csv...") | ||
fileview_df = pd.read_csv(update_df) | ||
else: | ||
# Fetch the project view data | ||
pending_projects_df = syn.tableQuery(f"SELECT id FROM {PROJECT_VIEW_ID} WHERE dataStatus='Data Pending'").asDataFrame() | ||
ids = tuple(pending_projects_df['id']) | ||
QUERY_IDS = f"({', '.join(repr(item) for item in ids)})" | ||
|
||
# Fetch the file view data | ||
# We'll need to filter out files created by nf-osi service or staff | ||
# who tend to upload data sharing plans & other administrative files | ||
print(f"Checking production table for {len(ids)} projects with status 'Data Pending'...") | ||
fileview_df = syn.tableQuery(f"SELECT projectId,count(*) as N FROM {FILE_VIEW_ID} WHERE type='file' and createdBy not in ('3421893', '3459953', '3434950', '3342573') and projectId in {QUERY_IDS} group by projectId").asDataFrame() | ||
|
||
print(f"Found {len(fileview_df.index)} that qualifying for transition:") | ||
print(fileview_df) | ||
|
||
for idx, p in fileview_df.iterrows(): | ||
project_to_update = syn.get(p['projectId']) | ||
print(f"Project {project_to_update['name']} has seen its first contribution of {p['N']} file(s)!") | ||
project_to_update['dataStatus'] = ['Under Embargo'] | ||
if dry_run: | ||
print("Modified project meta (not stored):") | ||
print(project_to_update) | ||
else: | ||
syn.store(project_to_update) | ||
print(f"Project {project_to_update['name']} had dataStatus changed to 'Under Embargo'") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--dry", action="store_true", help="Print project with modified metadata but do not store.") | ||
parser.add_argument("--update_df", type = str, help="Path to csv of projects to update.") | ||
args = parser.parse_args() | ||
main(dry_run = args.dry, update_df = args.update_df) |
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.
Should we maintain a table on the portal backend project to keep the createdBy principal ids in? Then we could also use that table for reporting (instead of the one listed in the readme here https://github.com/nf-osi/internal-reports)
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.
Yeah, we probably need to start a table as a source of truth for who should be excluded for these sorts of things. I think we can do that first and then go back to revise these two + others.