Skip to content
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 support relative dates in --since/--until #2059

Merged
merged 2 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.D/2059.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow to specify date and time in --since/--until relatively to current moment. For example,
`neuro ps --since 1d` will show jobs that were created during last day.
16 changes: 8 additions & 8 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,10 @@ Name | Description|
|_\-o, --owner TEXT_|Filter out jobs by owner \(multiple option). Supports `ME` option to filter by the current user.|
|_\-q, --quiet_|Run command in quiet mode \(DEPRECATED)|
|_\--recent-first / --recent-last_|Show newer jobs first or last|
|_--since DATE_|Show jobs created after a specific date \(including).|
|_--since DATE\_OR_TIMEDELTA_|Show jobs created after a specific date \(including). Use value of format '1d2h3m4s' to specify moment in past relatively to current time.|
|_\-s, --status \[pending | suspended | running | succeeded | failed | cancelled]_|Filter out jobs by status \(multiple option).|
|_\-t, --tag TAG_|Filter out jobs by tag \(multiple option)|
|_--until DATE_|Show jobs created before a specific date \(including).|
|_--until DATE\_OR_TIMEDELTA_|Show jobs created before a specific date \(including). Use value of format '1d2h3m4s' to specify moment in past relatively to current time.|
|_\-w, --wide_|Do not cut long lines for terminal width.|


Expand Down Expand Up @@ -772,11 +772,11 @@ Name | Description|
|_\--full-uri_|Output full image URI.|
|_\-n, --name NAME_|Filter out jobs by name.|
|_\-o, --owner TEXT_|Filter out jobs by owner \(multiple option). Supports `ME` option to filter by the current user. Specify `ALL` to show jobs of all users.|
|_--since DATE_|Show jobs created after a specific date \(including).|
|_--since DATE\_OR_TIMEDELTA_|Show jobs created after a specific date \(including). Use value of format '1d2h3m4s' to specify moment in past relatively to current time.|
|_--sort COLUMNS_|Sort rows by specified column. Add "-" prefix to revert the sorting order. Multiple columns can be specified \(comma separated). \[default: cpu]|
|_\-t, --tag TAG_|Filter out jobs by tag \(multiple option)|
|_--timeout FLOAT_|Maximum allowed time for executing the command, 0 for no timeout \[default: 0]|
|_--until DATE_|Show jobs created before a specific date \(including).|
|_--until DATE\_OR_TIMEDELTA_|Show jobs created before a specific date \(including). Use value of format '1d2h3m4s' to specify moment in past relatively to current time.|



Expand Down Expand Up @@ -2325,10 +2325,10 @@ Name | Description|
|_\-o, --owner TEXT_|Filter out jobs by owner \(multiple option). Supports `ME` option to filter by the current user.|
|_\-q, --quiet_|Run command in quiet mode \(DEPRECATED)|
|_\--recent-first / --recent-last_|Show newer jobs first or last|
|_--since DATE_|Show jobs created after a specific date \(including).|
|_--since DATE\_OR_TIMEDELTA_|Show jobs created after a specific date \(including). Use value of format '1d2h3m4s' to specify moment in past relatively to current time.|
|_\-s, --status \[pending | suspended | running | succeeded | failed | cancelled]_|Filter out jobs by status \(multiple option).|
|_\-t, --tag TAG_|Filter out jobs by tag \(multiple option)|
|_--until DATE_|Show jobs created before a specific date \(including).|
|_--until DATE\_OR_TIMEDELTA_|Show jobs created before a specific date \(including). Use value of format '1d2h3m4s' to specify moment in past relatively to current time.|
|_\-w, --wide_|Do not cut long lines for terminal width.|


Expand Down Expand Up @@ -2514,11 +2514,11 @@ Name | Description|
|_\--full-uri_|Output full image URI.|
|_\-n, --name NAME_|Filter out jobs by name.|
|_\-o, --owner TEXT_|Filter out jobs by owner \(multiple option). Supports `ME` option to filter by the current user. Specify `ALL` to show jobs of all users.|
|_--since DATE_|Show jobs created after a specific date \(including).|
|_--since DATE\_OR_TIMEDELTA_|Show jobs created after a specific date \(including). Use value of format '1d2h3m4s' to specify moment in past relatively to current time.|
|_--sort COLUMNS_|Sort rows by specified column. Add "-" prefix to revert the sorting order. Multiple columns can be specified \(comma separated). \[default: cpu]|
|_\-t, --tag TAG_|Filter out jobs by tag \(multiple option)|
|_--timeout FLOAT_|Maximum allowed time for executing the command, 0 for no timeout \[default: 0]|
|_--until DATE_|Show jobs created before a specific date \(including).|
|_--until DATE\_OR_TIMEDELTA_|Show jobs created before a specific date \(including). Use value of format '1d2h3m4s' to specify moment in past relatively to current time.|



Expand Down
8 changes: 4 additions & 4 deletions neuro-cli/docs/job.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ $ neuro ps -t tag1 -t tag2
| _-o, --owner TEXT_ | Filter out jobs by owner \(multiple option\). Supports `ME` option to filter by the current user. |
| _-q, --quiet_ | Run command in quiet mode \(DEPRECATED\) |
| _--recent-first / --recent-last_ | Show newer jobs first or last |
| _--since DATE_ | Show jobs created after a specific date \(including\). |
| _--since DATE\_OR\_TIMEDELTA_ | Show jobs created after a specific date \(including\). Use value of format '1d2h3m4s' to specify moment in past relatively to current time. |
| _-s, --status \[pending | suspended | running | succeeded | failed | cancelled\]_ | Filter out jobs by status \(multiple option\). |
| _-t, --tag TAG_ | Filter out jobs by tag \(multiple option\) |
| _--until DATE_ | Show jobs created before a specific date \(including\). |
| _--until DATE\_OR\_TIMEDELTA_ | Show jobs created before a specific date \(including\). Use value of format '1d2h3m4s' to specify moment in past relatively to current time. |
| _-w, --wide_ | Do not cut long lines for terminal width. |


Expand Down Expand Up @@ -341,11 +341,11 @@ $ neuro top -t tag1 -t tag2
| _--full-uri_ | Output full image URI. |
| _-n, --name NAME_ | Filter out jobs by name. |
| _-o, --owner TEXT_ | Filter out jobs by owner \(multiple option\). Supports `ME` option to filter by the current user. Specify `ALL` to show jobs of all users. |
| _--since DATE_ | Show jobs created after a specific date \(including\). |
| _--since DATE\_OR\_TIMEDELTA_ | Show jobs created after a specific date \(including\). Use value of format '1d2h3m4s' to specify moment in past relatively to current time. |
| _--sort COLUMNS_ | Sort rows by specified column. Add "-" prefix to revert the sorting order. Multiple columns can be specified \(comma separated\). _\[default: cpu\]_ |
| _-t, --tag TAG_ | Filter out jobs by tag \(multiple option\) |
| _--timeout FLOAT_ | Maximum allowed time for executing the command, 0 for no timeout _\[default: 0\]_ |
| _--until DATE_ | Show jobs created before a specific date \(including\). |
| _--until DATE\_OR\_TIMEDELTA_ | Show jobs created before a specific date \(including\). Use value of format '1d2h3m4s' to specify moment in past relatively to current time. |



Expand Down
8 changes: 4 additions & 4 deletions neuro-cli/docs/shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ $ neuro ps -t tag1 -t tag2
| _-o, --owner TEXT_ | Filter out jobs by owner \(multiple option\). Supports `ME` option to filter by the current user. |
| _-q, --quiet_ | Run command in quiet mode \(DEPRECATED\) |
| _--recent-first / --recent-last_ | Show newer jobs first or last |
| _--since DATE_ | Show jobs created after a specific date \(including\). |
| _--since DATE\_OR\_TIMEDELTA_ | Show jobs created after a specific date \(including\). Use value of format '1d2h3m4s' to specify moment in past relatively to current time. |
| _-s, --status \[pending | suspended | running | succeeded | failed | cancelled\]_ | Filter out jobs by status \(multiple option\). |
| _-t, --tag TAG_ | Filter out jobs by tag \(multiple option\) |
| _--until DATE_ | Show jobs created before a specific date \(including\). |
| _--until DATE\_OR\_TIMEDELTA_ | Show jobs created before a specific date \(including\). Use value of format '1d2h3m4s' to specify moment in past relatively to current time. |
| _-w, --wide_ | Do not cut long lines for terminal width. |


Expand Down Expand Up @@ -331,11 +331,11 @@ $ neuro top -t tag1 -t tag2
| _--full-uri_ | Output full image URI. |
| _-n, --name NAME_ | Filter out jobs by name. |
| _-o, --owner TEXT_ | Filter out jobs by owner \(multiple option\). Supports `ME` option to filter by the current user. Specify `ALL` to show jobs of all users. |
| _--since DATE_ | Show jobs created after a specific date \(including\). |
| _--since DATE\_OR\_TIMEDELTA_ | Show jobs created after a specific date \(including\). Use value of format '1d2h3m4s' to specify moment in past relatively to current time. |
| _--sort COLUMNS_ | Sort rows by specified column. Add "-" prefix to revert the sorting order. Multiple columns can be specified \(comma separated\). _\[default: cpu\]_ |
| _-t, --tag TAG_ | Filter out jobs by tag \(multiple option\) |
| _--timeout FLOAT_ | Maximum allowed time for executing the command, 0 for no timeout _\[default: 0\]_ |
| _--until DATE_ | Show jobs created before a specific date \(including\). |
| _--until DATE\_OR\_TIMEDELTA_ | Show jobs created before a specific date \(including\). Use value of format '1d2h3m4s' to specify moment in past relatively to current time. |



Expand Down
33 changes: 24 additions & 9 deletions neuro-cli/src/neuro_cli/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,17 @@ async def attach(root: Root, job: str, port_forward: List[Tuple[int, int]]) -> N
)
@option(
"--since",
metavar="DATE",
help="Show jobs created after a specific date (including).",
metavar="DATE_OR_TIMEDELTA",
help="Show jobs created after a specific date (including). "
"Use value of format '1d2h3m4s' to specify moment in "
"past relatively to current time.",
)
@option(
"--until",
metavar="DATE",
help="Show jobs created before a specific date (including).",
metavar="DATE_OR_TIMEDELTA",
help="Show jobs created before a specific date (including). "
"Use value of format '1d2h3m4s' to specify moment in "
"past relatively to current time.",
)
@option(
"-a",
Expand Down Expand Up @@ -547,13 +551,17 @@ async def browse(root: Root, job: str) -> None:
)
@option(
"--since",
metavar="DATE",
help="Show jobs created after a specific date (including).",
metavar="DATE_OR_TIMEDELTA",
help="Show jobs created after a specific date (including). "
"Use value of format '1d2h3m4s' to specify moment in "
"past relatively to current time.",
)
@option(
"--until",
metavar="DATE",
help="Show jobs created before a specific date (including).",
metavar="DATE_OR_TIMEDELTA",
help="Show jobs created before a specific date (including). "
"Use value of format '1d2h3m4s' to specify moment in "
"past relatively to current time.",
)
@option(
"--sort",
Expand Down Expand Up @@ -1336,7 +1344,14 @@ def _parse_date(value: str) -> Optional[datetime]:
try:
return isoparse(value)
except ValueError:
raise ValueError("Date should be in ISO-8601 format")
try:
delta = parse_timedelta(value)
return datetime.now(timezone.utc) - delta
except click.UsageError:
raise ValueError(
"Date should be either in ISO-8601 format or "
"relative delta of form 1d2h3m4s"
)
else:
return None

Expand Down