taskex 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- taskex-0.0.1/LICENSE +21 -0
- taskex-0.0.1/PKG-INFO +33 -0
- taskex-0.0.1/README.md +2 -0
- taskex-0.0.1/pyproject.toml +19 -0
- taskex-0.0.1/setup.cfg +4 -0
- taskex-0.0.1/taskex/__init__.py +4 -0
- taskex-0.0.1/taskex/env.py +30 -0
- taskex-0.0.1/taskex/models/__init__.py +6 -0
- taskex-0.0.1/taskex/models/run_status.py +23 -0
- taskex-0.0.1/taskex/models/shell_process.py +36 -0
- taskex-0.0.1/taskex/models/task_run.py +26 -0
- taskex-0.0.1/taskex/models/task_status.py +11 -0
- taskex-0.0.1/taskex/models/task_type.py +6 -0
- taskex-0.0.1/taskex/run.py +473 -0
- taskex-0.0.1/taskex/snowflake/__init__.py +1 -0
- taskex-0.0.1/taskex/snowflake/constants.py +3 -0
- taskex-0.0.1/taskex/snowflake/snowflake.py +47 -0
- taskex-0.0.1/taskex/snowflake/snowflake_generator.py +49 -0
- taskex-0.0.1/taskex/task.py +431 -0
- taskex-0.0.1/taskex/task_runner.py +304 -0
- taskex-0.0.1/taskex/util/__init__.py +1 -0
- taskex-0.0.1/taskex/util/time_parser.py +27 -0
- taskex-0.0.1/taskex.egg-info/PKG-INFO +33 -0
- taskex-0.0.1/taskex.egg-info/SOURCES.txt +24 -0
- taskex-0.0.1/taskex.egg-info/dependency_links.txt +1 -0
- taskex-0.0.1/taskex.egg-info/top_level.txt +1 -0
taskex-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ada Lündhé
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
taskex-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: taskex
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A pure Python library for running tasks asynchronously
|
|
5
|
+
Author-email: Ada Lundhe <adalundhe@lundhe.audio>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Ada Lündhé
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Requires-Python: >=3.11
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
|
|
32
|
+
# taskex
|
|
33
|
+
A library for running Python code or shell commands as tasks.
|
taskex-0.0.1/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "taskex"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "A pure Python library for running tasks asynchronously"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
authors = [
|
|
8
|
+
{name = "Ada Lundhe", email = "adalundhe@lundhe.audio"}
|
|
9
|
+
]
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
[build-system]
|
|
14
|
+
requires = ["setuptools>=61.0"]
|
|
15
|
+
build-backend = "setuptools.build_meta"
|
|
16
|
+
|
|
17
|
+
[tool.pytest.ini_options]
|
|
18
|
+
asyncio_mode = "strict"
|
|
19
|
+
asyncio_default_fixture_loop_scope = "function"
|
taskex-0.0.1/setup.cfg
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from typing import Callable, Dict, Union, Literal
|
|
2
|
+
|
|
3
|
+
import psutil
|
|
4
|
+
from pydantic import BaseModel, StrictInt, StrictStr
|
|
5
|
+
PrimaryType = Union[str, int, float, bytes, bool]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Env(BaseModel):
|
|
9
|
+
MERCURY_SYNC_EXECUTOR_TYPE: Literal['thread', 'process'] = 'process'
|
|
10
|
+
MERCURY_SYNC_LOG_LEVEL: StrictStr = "info"
|
|
11
|
+
MERCURY_SYNC_CLEANUP_INTERVAL: StrictStr = '1s'
|
|
12
|
+
MERCURY_SYNC_TASK_RUNNER_MAX_THREADS: StrictInt = psutil.cpu_count(logical=False)
|
|
13
|
+
MERCURY_SYNC_MAX_RUNNING_WORKFLOWS: StrictInt = 1
|
|
14
|
+
MERCURY_SYNC_MAX_PENDING_WORKFLOWS: StrictInt = 100
|
|
15
|
+
MERCURY_SYNC_CONTEXT_POLL_RATE: StrictStr = "0.1s"
|
|
16
|
+
MERCURY_SYNC_SHUTDOWN_POLL_RATE: StrictStr = "0.1s"
|
|
17
|
+
MERCURY_SYNC_DUPLICATE_JOB_POLICY: Literal["reject", "replace"] = "replace"
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def types_map(self) -> Dict[str, Callable[[str], PrimaryType]]:
|
|
21
|
+
return {
|
|
22
|
+
"MERCURY_SYNC_EXECUTOR_TYPE": str,
|
|
23
|
+
"MERCURY_SYNC_CLEANUP_INTERVAL": str,
|
|
24
|
+
"MERCURY_SYNC_LOG_LEVEL": str,
|
|
25
|
+
"MERCURY_SYNC_TASK_RUNNER_MAX_THREADS": int,
|
|
26
|
+
"MERCURY_SYNC_MAX_WORKFLOWS": int,
|
|
27
|
+
"MERCURY_SYNC_CONTEXT_POLL_RATE": str,
|
|
28
|
+
"MERCURY_SYNC_SHUTDOWN_POLL_RATE": str,
|
|
29
|
+
"MERCURY_SYNC_DUPLICATE_JOB_POLICY": str,
|
|
30
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
from .run_status import RunStatus as RunStatus
|
|
2
|
+
from .shell_process import ShellProcess as ShellProcess
|
|
3
|
+
from .shell_process import CommandType as CommandType
|
|
4
|
+
from .task_run import TaskRun as TaskRun
|
|
5
|
+
from .task_status import TaskStatus as TaskStatus
|
|
6
|
+
from .task_type import TaskType as TaskType
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from typing import Literal
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class RunStatus(Enum):
|
|
6
|
+
CREATED = "CREATED"
|
|
7
|
+
PENDING = "PENDING"
|
|
8
|
+
IDLE = "IDLE"
|
|
9
|
+
RUNNING = "RUNNING"
|
|
10
|
+
COMPLETE = "COMPLETE"
|
|
11
|
+
CANCELLED = "CANCELLED"
|
|
12
|
+
FAILED = "FAILED"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
RunStatusName = Literal[
|
|
16
|
+
'CREATED',
|
|
17
|
+
'PENDING',
|
|
18
|
+
'IDLE',
|
|
19
|
+
'RUNNING',
|
|
20
|
+
'COMPLETE',
|
|
21
|
+
'CANCELLED',
|
|
22
|
+
'FAILED',
|
|
23
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from pydantic import (
|
|
3
|
+
BaseModel,
|
|
4
|
+
StrictInt,
|
|
5
|
+
StrictFloat,
|
|
6
|
+
StrictStr,
|
|
7
|
+
StrictBytes,
|
|
8
|
+
)
|
|
9
|
+
from typing import Literal, Any, Dict, Tuple
|
|
10
|
+
from .run_status import RunStatus
|
|
11
|
+
from .task_type import TaskType
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
CommandType = Literal['shell', 'subprocess']
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ShellProcess(BaseModel):
|
|
18
|
+
run_id: StrictInt
|
|
19
|
+
process_id: StrictInt
|
|
20
|
+
command: StrictStr
|
|
21
|
+
status: RunStatus
|
|
22
|
+
args: Tuple[str, ...] | None = None
|
|
23
|
+
return_code: StrictInt | None = None
|
|
24
|
+
env: Dict[str, Any] | None = None
|
|
25
|
+
working_directory: StrictStr | None = None
|
|
26
|
+
command_type: CommandType = 'subprocess'
|
|
27
|
+
error: StrictStr | StrictBytes | None = None
|
|
28
|
+
trace: StrictStr | StrictBytes | None = None
|
|
29
|
+
start: StrictInt | StrictFloat = time.monotonic()
|
|
30
|
+
end: StrictInt | StrictFloat | None = None
|
|
31
|
+
elapsed: StrictInt | StrictFloat = 0
|
|
32
|
+
result: StrictStr | StrictBytes | None = None
|
|
33
|
+
task_type: TaskType = TaskType.SHELL
|
|
34
|
+
|
|
35
|
+
def complete(self):
|
|
36
|
+
return self.status in [RunStatus.COMPLETE, RunStatus.CANCELLED, RunStatus.FAILED]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from typing import Any, Optional
|
|
3
|
+
from pydantic import (
|
|
4
|
+
BaseModel,
|
|
5
|
+
StrictFloat,
|
|
6
|
+
StrictInt,
|
|
7
|
+
StrictStr,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
from .run_status import RunStatus
|
|
11
|
+
from .task_type import TaskType
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TaskRun(BaseModel):
|
|
15
|
+
run_id: StrictInt
|
|
16
|
+
status: RunStatus
|
|
17
|
+
error: Optional[StrictStr] = None
|
|
18
|
+
trace: Optional[StrictStr] = None
|
|
19
|
+
start: StrictInt | StrictFloat = time.monotonic()
|
|
20
|
+
end: Optional[StrictInt | StrictFloat] = None
|
|
21
|
+
elapsed: StrictInt | StrictFloat = 0
|
|
22
|
+
result: Optional[Any] = None
|
|
23
|
+
task_type: TaskType = TaskType.CALLABLE
|
|
24
|
+
|
|
25
|
+
def complete(self):
|
|
26
|
+
return self.status in [RunStatus.COMPLETE, RunStatus.CANCELLED, RunStatus.FAILED]
|