Skip to content

Commit

Permalink
Add ability to filter out expired jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
tylere committed Mar 25, 2024
1 parent 86df824 commit c6f35a5
Show file tree
Hide file tree
Showing 4 changed files with 412 additions and 79 deletions.
53 changes: 51 additions & 2 deletions 00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
"outputs": [],
"source": [
"#| export\n",
"import ee\n",
"import logging"
"import datetime\n",
"from dateutil import parser\n",
"import logging\n",
"\n",
"import ee"
]
},
{
Expand All @@ -63,6 +66,45 @@
" raise(e)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"def filter_jobs(\n",
" # hyp3_batch,\n",
" jobs,\n",
" expired=None,\n",
" status_code=None,\n",
"):\n",
" \"Filter ASF batch jobs by specified criteria.\"\n",
" # jobs = hyp3_batch.jobs\n",
" # Filter by expiration status.\n",
" if expired is False:\n",
" jobs = [\n",
" job for job in jobs\n",
" if parser.parse(job.to_dict()['expiration_time']) > datetime.datetime.now(datetime.timezone.utc)\n",
" ]\n",
" elif expired is True:\n",
" jobs = [\n",
" job for job in jobs\n",
" if parser.parse(job.to_dict()['expiration_time']) <= datetime.datetime.now(datetime.timezone.utc)\n",
" ]\n",
" # Filter by status code.\n",
" if isinstance(status_code, str):\n",
" print('Status code is a string')\n",
" status_code = [status_code]\n",
" if isinstance(status_code, list):\n",
" print('Status code is a list')\n",
" jobs = [\n",
" job for job in jobs\n",
" if job.to_dict()['status_code'] in status_code\n",
" ]\n",
" return jobs"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -72,6 +114,13 @@
"#| hide\n",
"import nbdev; nbdev.nbdev_export()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit c6f35a5

Please sign in to comment.