Skip to content
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
5 changes: 2 additions & 3 deletions generator_config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
project_name_override: taskbadger-python
package_name_override: taskbadger/internal
post_hooks:
- "autoflake -i -r --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports ."
- "isort ."
- "black ."
- "ruff format ."
- "ruff check . --fix"
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.ruff.lint.per-file-ignores]
"taskbadger/internal/*" = ["E501"]
122 changes: 64 additions & 58 deletions taskbadger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,23 @@ paths:
examples:
ListResponse:
value:
previous: string
next: string
next: http://api.example.org/accounts/?cursor=cD00ODY%3D"
previous: http://api.example.org/accounts/?cursor=cj0xJnA9NDg3
results:
- id: 57ae8eVBrH7jbDgmYj6Ut2vR9S
organization: example_org
project: example_org
name: example task
status: processing
value: 63
value_percent: 63
data:
property1: customValue
created: '2022-08-24T14:15:22Z'
updated: '2022-08-24T16:15:22Z'
- previous: string
next: string
results:
- id: 57ae8eVBrH7jbDgmYj6Ut2vR9S
organization: example_org
project: example_org
name: example task
status: processing
value: 63
value_percent: 63
data:
property1: customValue
created: '2022-08-24T14:15:22Z'
updated: '2022-08-24T16:15:22Z'
summary: List Response
description: ''
post:
Expand Down Expand Up @@ -100,6 +103,9 @@ paths:
status: pending
data:
property1: customValue
tags:
project: demo
user: admin
summary: Create Payload
required: true
security:
Expand Down Expand Up @@ -601,9 +607,7 @@ components:
status:
type: string
readOnly: true
config:
type: object
additionalProperties: {}
config: {}
created:
type: string
format: date-time
Expand Down Expand Up @@ -631,21 +635,25 @@ components:
type: string
minLength: 1
maxLength: 50
config:
type: object
additionalProperties: {}
config: {}
required:
- integration
- trigger
PaginatedTaskList:
type: object
required:
- results
properties:
next:
type: string
nullable: true
format: uri
example: http://api.example.org/accounts/?cursor=cD00ODY%3D"
previous:
type: string
nullable: true
format: uri
example: http://api.example.org/accounts/?cursor=cj0xJnA9NDg3
results:
type: array
items:
Expand All @@ -661,9 +669,7 @@ components:
type: string
minLength: 1
maxLength: 50
config:
type: object
additionalProperties: {}
config: {}
PatchedTaskRequest:
type: object
properties:
Expand All @@ -675,15 +681,6 @@ components:
status:
allOf:
- $ref: '#/components/schemas/StatusEnum'
description: |-
* `pending` - pending
* `pre_processing` - pre_processing
* `processing` - processing
* `post_processing` - post_processing
* `success` - success
* `error` - error
* `cancelled` - cancelled
* `stale` - stale
default: pending
value:
type: integer
Expand All @@ -699,8 +696,6 @@ components:
format: int64
description: Maximum value of the task. Defaults to 100.
data:
type: object
additionalProperties: {}
nullable: true
description: Custom metadata
start_time:
Expand Down Expand Up @@ -728,7 +723,15 @@ components:
minimum: 1
nullable: true
description: Maximum time to allow between task updates before considering
the task stale. Only applies when task is in a running state. (seconds)
the task stale. (seconds)
tags:
type: object
additionalProperties:
type: string
minLength: 2
maxLength: 255
description: Tags for the task represented as a mapping from 'namespace'
to 'value'.
StatusEnum:
enum:
- pending
Expand All @@ -740,6 +743,15 @@ components:
- cancelled
- stale
type: string
description: |-
* `pending` - pending
* `pre_processing` - pre_processing
* `processing` - processing
* `post_processing` - post_processing
* `success` - success
* `error` - error
* `cancelled` - cancelled
* `stale` - stale
Task:
type: object
properties:
Expand All @@ -760,15 +772,6 @@ components:
status:
allOf:
- $ref: '#/components/schemas/StatusEnum'
description: |-
* `pending` - pending
* `pre_processing` - pre_processing
* `processing` - processing
* `post_processing` - post_processing
* `success` - success
* `error` - error
* `cancelled` - cancelled
* `stale` - stale
default: pending
value:
type: integer
Expand All @@ -788,8 +791,6 @@ components:
readOnly: true
nullable: true
data:
type: object
additionalProperties: {}
nullable: true
description: Custom metadata
created:
Expand Down Expand Up @@ -825,13 +826,21 @@ components:
minimum: 1
nullable: true
description: Maximum time to allow between task updates before considering
the task stale. Only applies when task is in a running state. (seconds)
the task stale. (seconds)
url:
type: string
readOnly: true
public_url:
type: string
readOnly: true
tags:
type: object
additionalProperties:
type: string
maxLength: 255
minLength: 2
description: Tags for the task represented as a mapping from 'namespace'
to 'value'.
required:
- created
- id
Expand All @@ -853,15 +862,6 @@ components:
status:
allOf:
- $ref: '#/components/schemas/StatusEnum'
description: |-
* `pending` - pending
* `pre_processing` - pre_processing
* `processing` - processing
* `post_processing` - post_processing
* `success` - success
* `error` - error
* `cancelled` - cancelled
* `stale` - stale
default: pending
value:
type: integer
Expand All @@ -877,8 +877,6 @@ components:
format: int64
description: Maximum value of the task. Defaults to 100.
data:
type: object
additionalProperties: {}
nullable: true
description: Custom metadata
start_time:
Expand Down Expand Up @@ -906,7 +904,15 @@ components:
minimum: 1
nullable: true
description: Maximum time to allow between task updates before considering
the task stale. Only applies when task is in a running state. (seconds)
the task stale. (seconds)
tags:
type: object
additionalProperties:
type: string
minLength: 2
maxLength: 255
description: Tags for the task represented as a mapping from 'namespace'
to 'value'.
required:
- name
securitySchemes:
Expand Down
30 changes: 27 additions & 3 deletions taskbadger/cli/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
configure_api,
err_console,
get_actions,
get_metadata,
merge_kv_json,
)


Expand Down Expand Up @@ -69,12 +69,23 @@ def create(
show_default=False,
help="Metadata to associate with the task. Must be valid JSON.",
),
tag: list[str] = typer.Option(
None,
show_default=False,
help="Metadata 'key=value' pair to associate with the task. Can be specified multiple times.",
),
tags_json: str = typer.Option(
None,
show_default=False,
help="Tags to associate with the task. Must be valid JSON mapping name -> value.",
),
quiet: bool = typer.Option(False, "--quiet", "-q", help="Minimal output. Only the Task ID."),
):
"""Create a task."""
configure_api(ctx)
actions = get_actions(action_def)
metadata = get_metadata(metadata, metadata_json)
metadata = merge_kv_json(metadata, metadata_json)
tags = merge_kv_json(tag, tags_json)

try:
task = create_task(
Expand All @@ -84,6 +95,7 @@ def create(
data=metadata,
actions=actions,
monitor_id=monitor_id,
tags=tags,
)
except Exception as e:
err_console.print(f"Error creating task: {e}")
Expand Down Expand Up @@ -119,12 +131,23 @@ def update(
show_default=False,
help="Metadata to associate with the task. Must be valid JSON.",
),
tag: list[str] = typer.Option(
None,
show_default=False,
help="Metadata 'key=value' pair to associate with the task. Can be specified multiple times.",
),
tags_json: str = typer.Option(
None,
show_default=False,
help="Tags to associate with the task. Must be valid JSON mapping name -> value.",
),
quiet: bool = typer.Option(False, "--quiet", "-q", help="No output."),
):
"""Update a task."""
configure_api(ctx)
actions = get_actions(action_def)
metadata = get_metadata(metadata, metadata_json)
metadata = merge_kv_json(metadata, metadata_json)
tags = merge_kv_json(tag, tags_json)

try:
task = update_task(
Expand All @@ -135,6 +158,7 @@ def update(
value_max=value_max,
data=metadata,
actions=actions,
tags=tags,
)
except Exception as e:
err_console.print(f"Error creating task: {e}")
Expand Down
2 changes: 1 addition & 1 deletion taskbadger/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_actions(action_def: tuple[str, str, str]) -> list[Action]:
return []


def get_metadata(metadata_kv: list[str], metadata_json: str) -> dict:
def merge_kv_json(metadata_kv: list[str], metadata_json: str) -> dict:
metadata = {}
for kv in metadata_kv:
k, v = kv.strip().split("=", 1)
Expand Down
9 changes: 8 additions & 1 deletion taskbadger/cli/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rich import print

from taskbadger import DefaultMergeStrategy, Session, StatusEnum, Task
from taskbadger.cli.utils import configure_api, err_console, get_actions
from taskbadger.cli.utils import configure_api, err_console, get_actions, merge_kv_json
from taskbadger.process import ProcessRunner


Expand All @@ -19,6 +19,11 @@ def run(
show_default=False,
help="Action definition e.g. 'success,error email to:me@email.com'",
),
tag: list[str] = typer.Option(
None,
show_default=False,
help="Tags: 'name=value' pair to associate with the task. Can be specified multiple times.",
),
capture_output: bool = typer.Option(False, help="Capture stdout and stderr."),
):
"""Execute a command using the CLI and create a Task to track its outcome.
Expand All @@ -34,6 +39,7 @@ def run(
"""
configure_api(ctx)
actions = get_actions(action_def)
tags = merge_kv_json(tag, "")
stale_timeout = update_frequency * 2
with Session():
try:
Expand All @@ -43,6 +49,7 @@ def run(
stale_timeout=stale_timeout,
actions=actions,
monitor_id=monitor_id,
tags=tags,
)
except Exception as e:
err_console.print(f"Error creating task: {e}")
Expand Down
Loading