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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "inventory_job"
description = "Destination inventory."
select = "stg_orders"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""A sensor declared inside a private support folder fails compile instead of never running."""

from sqlbuild.orchestration import NodeEventKind, node_event, sensor

on_orders = sensor(
"on_orders_sensor",
description="Build inventory for every genuine orders rebuild.",
when=node_event(select="orders orders*", kinds=[NodeEventKind.SUCCESS]),
run="inventory_job",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "inventory_job"
description = "Destination inventory."
select = "stg_orders"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Private support: modules in a _-prefixed folder declare nothing."""

ORDERS_SELECTION: str = "orders orders*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""A sensor in its domain folder reads its selection from a private support folder."""

from orchestration.sensors.inventory._helpers.selection import ORDERS_SELECTION

from sqlbuild.orchestration import NodeEventKind, node_event, sensor

on_orders = sensor(
"on_orders_sensor",
description="Build inventory for every genuine orders rebuild.",
when=node_event(select=ORDERS_SELECTION, kinds=[NodeEventKind.SUCCESS]),
run="inventory_job",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "restock_shipments_job"
description = "Rebuild shipments."
select = "shipments"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Shipment backlog settings."""

BACKLOG_REASON: str = "No shipment backlog"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Skip reasons for the fulfillment sensors."""


def prefixed(reason: str) -> str:
"""Prefix a skip reason with its domain."""
return f"fulfillment: {reason}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Skip restocking while the shipment backlog is empty."""

from orchestration.sensors.fulfillment._constants import BACKLOG_REASON
from orchestration.sensors.fulfillment._helpers.reasons import prefixed

from sqlbuild.orchestration import SensorContext, SkipReason, sensor

_REASON_SUFFIX: str = "."


@sensor(
"shipment_backlog_sensor",
description="Rebuild shipments when the backlog grows.",
run="restock_shipments_job",
minimum_interval_seconds=60,
)
def shipment_backlog(ctx: SensorContext) -> SkipReason:
return SkipReason(prefixed(BACKLOG_REASON) + _REASON_SUFFIX)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Test cases for carrier money formatting."""

from dataclasses import dataclass


@dataclass(frozen=True)
class CentsTextTestCase:
"""One amount in cents and its carrier text."""

description: str
cents: int
expected_text: str
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Tests for carrier money formatting."""

import pytest
from python.utils.currency import amounts
from tests.python.utils.currency._test_types import CentsTextTestCase


@pytest.mark.parametrize(
"test_case",
[
CentsTextTestCase(
description="whole amounts keep two decimals", cents=1200, expected_text="12.00"
),
CentsTextTestCase(description="single cents are padded", cents=1205, expected_text="12.05"),
],
ids=lambda case: case.description,
)
def test_given_cents_when_formatting_then_returns_carrier_text(
test_case: CentsTextTestCase,
) -> None:
"""Format cents as carrier text."""
assert amounts.cents_text(test_case.cents) == test_case.expected_text
35 changes: 29 additions & 6 deletions benchmarks/duckshop/edge_cases/python_rules/expected_findings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"select": ["SQBRPYTHON", "SQBRPYTHON306"],
"findings": [
["SQBRPYTHON101", "hooks/python/alert.py", 4, 11],
["SQBRPYTHON301", "orchestration/sensors/inventory/_helpers/feed_window.py", 3, 1],
["SQBRPYTHON017", "orchestration/sensors/inventory/_helpers/feed_window.py", 3, 43],
["SQBRPYTHON017", "orchestration/sensors/inventory/_lib/age.py", 1, 1],
["SQBRPYTHON016", "orchestration/sensors/stock_feed.py", 1, 1],
["SQBRPYTHON019", "orchestration/sensors/stock_feed.py", 3, 8],
["SQBRPYTHON018", "orchestration/sensors/stock_feed.py", 7, 1],
["SQBRPYTHON020", "orchestration/sensors/stock_feed.py", 16, 5],
["SQBRPYTHON015", "providers/carrier_api/provider.py", 3, 8],
["SQBRPYTHON014", "providers/carrier_api/provider.py", 8, 5],
["SQBRPYTHON013", "providers/stock_feed.py", 1, 1],
Expand All @@ -12,16 +19,32 @@
["SQBRPYTHON306", "python/inventory/main/publish.py", 4, 1],
["SQBRPYTHON614", "python/inventory/replenishment.py", 1, 1],
["SQBRPYTHON012", "python/inventory/replenishment.py", 7, 5],
["SQBRPYTHON306", "python/inventory/restock/_helpers/thresholds.py", 6, 1],
["SQBRPYTHON306", "python/inventory/restock/_helpers/thresholds.py", 9, 1],
["SQBRPYTHON306", "python/inventory/restock/constants.py", 5, 1],
["SQBRPYTHON022", "python/inventory/restock/constants.py", 5, 38],
["SQBRPYTHON617", "python/inventory/restock/main.py", 1, 1],
["SQBRPYTHON306", "python/inventory/restock/main.py", 4, 1],
["SQBRPYTHON306", "python/inventory/restock/main.py", 9, 1],
["SQBRPYTHON003", "python/inventory/stock_count/node.py", 1, 1],
["SQBRPYTHON004", "python/inventory/stock_count/node.py", 5, 1],
["SQBRPYTHON605", "python/inventory/stock_count/node.py", 5, 1],
["SQBRPYTHON005", "python/inventory/stock_count/node.py", 9, 5],
["SQBRPYTHON007", "python/inventory/stock_count/node.py", 9, 5],
["SQBRPYTHON011", "python/inventory/stock_count/node.py", 9, 5],
["SQBRPYTHON008", "python/inventory/stock_count/node.py", 3, 62],
["SQBRPYTHON004", "python/inventory/stock_count/node.py", 7, 1],
["SQBRPYTHON605", "python/inventory/stock_count/node.py", 7, 1],
["SQBRPYTHON005", "python/inventory/stock_count/node.py", 11, 5],
["SQBRPYTHON007", "python/inventory/stock_count/node.py", 11, 5],
["SQBRPYTHON011", "python/inventory/stock_count/node.py", 11, 5],
["SQBRPYTHON001", "python/report.py", 1, 1],
["SQBRPYTHON614", "python/report.py", 1, 1]
["SQBRPYTHON614", "python/report.py", 1, 1],
["SQBRPYTHON021", "tests/python/inventory/test_restock_window.py", 1, 1],
["SQBRPYTHON710", "tests/python/inventory/test_restock_window.py", 1, 1],
["SQBRPYTHON722", "tests/python/inventory/test_restock_window.py", 6, 35],
["SQBRPYTHON712", "tests/python/inventory/test_restock_window.py", 7, 1],
["SQBRPYTHON714", "tests/python/inventory/test_restock_window.py", 7, 1],
["SQBRPYTHON715", "tests/python/inventory/test_restock_window.py", 7, 1],
["SQBRPYTHON716", "tests/python/inventory/test_restock_window.py", 7, 1],
["SQBRPYTHON718", "tests/python/inventory/test_restock_window.py", 7, 1],
["SQBRPYTHON719", "tests/python/inventory/test_restock_window.py", 7, 1],
["SQBRPYTHON724", "tests/python/inventory/test_restock_window.py", 7, 1],
["SQBRPYTHON704", "tests/python/inventory/test_restock_window.py", 9, 5]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "stock_count_job"
description = "Count stock."
select = "stock_count"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Shipment cut-off hours, private to the fulfillment sensors."""

CUTOFF_HOURS: int = 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Feed window that reads support private to another domain."""

from ...fulfillment._helpers.hours import CUTOFF_HOURS

FEED_WINDOW_HOURS: int = CUTOFF_HOURS * 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Private support in a folder other than _helpers/."""

FEED_AGE_HOURS: int = 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""A sensor outside a domain folder that documents itself twice and reads a node module."""

import python.report

from sqlbuild.orchestration import SensorContext, SkipReason, sensor

STALE_REASON: str = "Stock feed is fresh"


@sensor(
"stock_feed_stale_sensor",
description="Count stock when the supplier feed goes stale.",
run="stock_count_job",
minimum_interval_seconds=60,
)
def stock_feed_stale(ctx: SensorContext) -> SkipReason:
"""Count stock when the supplier feed goes stale."""
return SkipReason(f"{STALE_REASON} {python.report.__name__}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Read restock thresholds, from the stock service when asked to refresh."""

import json
import urllib.request

_DEFAULT_THRESHOLDS: dict[str, int] = {"north": 10, "south": 5}


def load_thresholds(refresh: bool = False) -> dict[str, int]:
"""Return each warehouse's restock threshold."""
if refresh:
return json.load(urllib.request.urlopen("https://example.com/thresholds"))
return dict(_DEFAULT_THRESHOLDS)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Restock thresholds per warehouse."""

from python.inventory.restock._helpers import thresholds

RESTOCK_THRESHOLDS: dict[str, int] = thresholds.load_thresholds()
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Count stock in every warehouse."""

from orchestration.sensors.fulfillment._helpers.hours import CUTOFF_HOURS

from sqlbuild.tasks import TaskContext, task

WAREHOUSES: tuple[str, ...] = ("north", "south")
Expand All @@ -8,4 +10,4 @@
@task
def stock_count(context: TaskContext) -> int:
"""Count stock in every warehouse."""
return len(WAREHOUSES)
return len(WAREHOUSES) + CUTOFF_HOURS
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Tests for a restock window that has no module."""

import pytest


@pytest.mark.parametrize("case", [{"days": 3, "expected": True}])
def test_window(case: dict[str, object]) -> None:
"""Check the restock window."""
if case["days"]:
assert case["expected"]
9 changes: 9 additions & 0 deletions clients/typescript/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,13 @@ export interface components {
healthy: boolean;
/** @enum {string} */
kind: "connection";
} | {
/** Format: int64 */
generation: number;
/** @enum {string} */
kind: "provider_secrets";
/** Format: int64 */
missing: number;
} | {
/** Format: int64 */
elapsed_millis: number;
Expand Down Expand Up @@ -2571,6 +2578,8 @@ export interface components {
description?: string | null;
/** @description The environment variable the setting is read from. */
env: string;
/** @description Whether this required secret is unset in the location's environment. */
missing?: boolean;
name: string;
required: boolean;
/** @description Whether the annotation is a pydantic secret type. */
Expand Down
Loading
Loading