compose-runner 0.6.5__py2.py3-none-any.whl → 0.7.0__py2.py3-none-any.whl
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.
- compose_runner/_version.py +2 -2
- compose_runner/aws_lambda/cost_check_handler.py +71 -0
- {compose_runner-0.6.5.dist-info → compose_runner-0.7.0.dist-info}/METADATA +2 -2
- {compose_runner-0.6.5.dist-info → compose_runner-0.7.0.dist-info}/RECORD +7 -6
- {compose_runner-0.6.5.dist-info → compose_runner-0.7.0.dist-info}/WHEEL +0 -0
- {compose_runner-0.6.5.dist-info → compose_runner-0.7.0.dist-info}/entry_points.txt +0 -0
- {compose_runner-0.6.5.dist-info → compose_runner-0.7.0.dist-info}/licenses/LICENSE +0 -0
compose_runner/_version.py
CHANGED
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '0.
|
|
32
|
-
__version_tuple__ = version_tuple = (0,
|
|
31
|
+
__version__ = version = '0.7.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 7, 0)
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import datetime as _dt
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
from decimal import Decimal
|
|
7
|
+
from typing import Any, Dict
|
|
8
|
+
|
|
9
|
+
import boto3
|
|
10
|
+
from botocore.exceptions import BotoCoreError, ClientError
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
logger.setLevel(logging.INFO)
|
|
14
|
+
|
|
15
|
+
_CE_CLIENT = boto3.client("ce", region_name=os.environ.get("AWS_REGION", "us-east-1"))
|
|
16
|
+
|
|
17
|
+
COST_LIMIT_ENV = "COST_LIMIT_USD"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _month_range(today: _dt.date) -> Dict[str, str]:
|
|
21
|
+
start = today.replace(day=1)
|
|
22
|
+
# Cost Explorer end date is exclusive; add a day to include today.
|
|
23
|
+
end = today + _dt.timedelta(days=1)
|
|
24
|
+
return {"Start": start.isoformat(), "End": end.isoformat()}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _current_month_cost() -> Dict[str, Any]:
|
|
28
|
+
period = _month_range(_dt.date.today())
|
|
29
|
+
response = _CE_CLIENT.get_cost_and_usage(
|
|
30
|
+
TimePeriod=period,
|
|
31
|
+
Granularity="MONTHLY",
|
|
32
|
+
Metrics=["UnblendedCost"],
|
|
33
|
+
)
|
|
34
|
+
results = response.get("ResultsByTime", [])
|
|
35
|
+
total = results[0]["Total"]["UnblendedCost"] if results else {"Amount": "0", "Unit": "USD"}
|
|
36
|
+
amount = float(Decimal(total.get("Amount", "0")))
|
|
37
|
+
currency = total.get("Unit", "USD")
|
|
38
|
+
return {"amount": amount, "currency": currency, "time_period": period}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
|
|
42
|
+
limit_raw = os.environ.get(COST_LIMIT_ENV)
|
|
43
|
+
if not limit_raw:
|
|
44
|
+
raise RuntimeError(f"{COST_LIMIT_ENV} environment variable must be set.")
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
limit = float(limit_raw)
|
|
48
|
+
except ValueError as exc: # noqa: PERF203
|
|
49
|
+
raise RuntimeError(f"Invalid {COST_LIMIT_ENV}: {limit_raw}") from exc
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
cost = _current_month_cost()
|
|
53
|
+
except (ClientError, BotoCoreError) as exc:
|
|
54
|
+
logger.error("Failed to query Cost Explorer: %s", exc)
|
|
55
|
+
return {
|
|
56
|
+
"status": "ERROR",
|
|
57
|
+
"allowed": False,
|
|
58
|
+
"error": "cost_explorer_unavailable",
|
|
59
|
+
"limit": limit,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
amount = cost["amount"]
|
|
63
|
+
allowed = amount < limit
|
|
64
|
+
return {
|
|
65
|
+
"status": "OK",
|
|
66
|
+
"allowed": allowed,
|
|
67
|
+
"current_spend": amount,
|
|
68
|
+
"limit": limit,
|
|
69
|
+
"currency": cost.get("currency", "USD"),
|
|
70
|
+
"time_period": cost.get("time_period"),
|
|
71
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: compose-runner
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: A package for running neurosynth-compose analyses
|
|
5
5
|
Project-URL: Repository, https://github.com/neurostuff/compose-runner
|
|
6
6
|
Author-email: James Kent <jamesdkent21@gmail.com>
|
|
@@ -10,7 +10,7 @@ Keywords: meta-analysis,neuroimaging,neurosynth,neurosynth-compose
|
|
|
10
10
|
Classifier: License :: OSI Approved :: BSD License
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Requires-Dist: click
|
|
13
|
-
Requires-Dist: nimare
|
|
13
|
+
Requires-Dist: nimare>=0.7.0
|
|
14
14
|
Requires-Dist: numpy
|
|
15
15
|
Requires-Dist: sentry-sdk
|
|
16
16
|
Provides-Extra: aws
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
compose_runner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
compose_runner/_version.py,sha256=
|
|
2
|
+
compose_runner/_version.py,sha256=uLbRjFSUZAgfl7V7O8zKV5Db36k7tz87ZIVq3l2SWs0,704
|
|
3
3
|
compose_runner/cli.py,sha256=1tkxFgEe8Yk7VkzE8qxGmCGqLU7UbGin2VaP0AiZkVg,1101
|
|
4
4
|
compose_runner/ecs_task.py,sha256=15CyLsaf2xrvWM-gGPDOXj_Hq8eJJPiH7xyRas93zn0,5352
|
|
5
5
|
compose_runner/run.py,sha256=wNAm8_fKoBJElMVlY7GTODqjZJG8S6y8K-QCUljL6Ko,18666
|
|
6
6
|
compose_runner/sentry.py,sha256=pjqwsZrXrKB0cCy-TL-_2eYJIqUU0aV-8e0SWUk-9Xw,320
|
|
7
7
|
compose_runner/aws_lambda/__init__.py,sha256=yZNXXv7gCPSrtLCEX5Qf4cnzSTS3fHPV6k-SyZwiZIA,48
|
|
8
8
|
compose_runner/aws_lambda/common.py,sha256=cA2G5lO4P8uVBqJaYcU6Y3P3t3syoTmk4SpLKZhAFo8,1688
|
|
9
|
+
compose_runner/aws_lambda/cost_check_handler.py,sha256=TjzlnXLOT7kW6RfYfXuFFpmusIckGjOeUM6y0_NztBw,2213
|
|
9
10
|
compose_runner/aws_lambda/log_poll_handler.py,sha256=eEU-Ra_-17me3e4eqSTd2Nv_qoaOl7zi3kIxD58Tbek,1905
|
|
10
11
|
compose_runner/aws_lambda/results_handler.py,sha256=vSxs4nbWyBmkFFKRGIp5-T4W2hPh9zgj7uNH-e18aW8,2107
|
|
11
12
|
compose_runner/aws_lambda/run_handler.py,sha256=WbaoRp5hsWNqAgDamW9BPihp1tfVVTM94_HKHL4Uawg,6562
|
|
@@ -22,8 +23,8 @@ compose_runner/tests/cassettes/test_run/test_run_database_workflow.yaml,sha256=a
|
|
|
22
23
|
compose_runner/tests/cassettes/test_run/test_run_group_comparison_workflow.yaml,sha256=FaZpMdcaM7TMgyueyZBGftm6ywUh1HhtGmCegXUmRFA,4029712
|
|
23
24
|
compose_runner/tests/cassettes/test_run/test_run_string_group_comparison_workflow.yaml,sha256=pcn6tQwrimhDtP8yJ3jFlsfEOnk8FWybYQr9IQ5A_KA,3233839
|
|
24
25
|
compose_runner/tests/cassettes/test_run/test_run_workflow.yaml,sha256=0Nk7eJWAmgYALG2ODrezbRhpYsc00JiuYVjXt3TUm5c,3857234
|
|
25
|
-
compose_runner-0.
|
|
26
|
-
compose_runner-0.
|
|
27
|
-
compose_runner-0.
|
|
28
|
-
compose_runner-0.
|
|
29
|
-
compose_runner-0.
|
|
26
|
+
compose_runner-0.7.0.dist-info/METADATA,sha256=IWlOS0ajYq6tG_JEEXTyw56DeLGZzOS9Pk6BcOKAtl0,3439
|
|
27
|
+
compose_runner-0.7.0.dist-info/WHEEL,sha256=aha0VrrYvgDJ3Xxl3db_g_MDIW-ZexDdrc_m-Hk8YY4,105
|
|
28
|
+
compose_runner-0.7.0.dist-info/entry_points.txt,sha256=TyPmB9o2tSWw8L3mcach9r2EL7inRVXE9ew3_XReMIY,55
|
|
29
|
+
compose_runner-0.7.0.dist-info/licenses/LICENSE,sha256=PeiWxrrRme2rIpPMV9vjgGe7UHEKCIcTb0KagYhnyqo,1313
|
|
30
|
+
compose_runner-0.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|