(
connection: sqlite3.Connection, args: argparse.Namespace
)
| 1900 | |
| 1901 | |
| 1902 | def claim_handoff_delivery( |
| 1903 | connection: sqlite3.Connection, args: argparse.Namespace |
| 1904 | ) -> dict[str, Any]: |
| 1905 | scan_id = require_uuid(args.scan_id, "scan-id") |
| 1906 | claim_token = require_handoff_claim_token(args.claim_token) |
| 1907 | timestamp = now() |
| 1908 | with connection: |
| 1909 | scan = require_scan(connection, scan_id) |
| 1910 | if scan["handoff_status"] != "pending" or scan["handoff_claim_token"] == claim_token: |
| 1911 | return workspace_state(connection, scan["workspace_id"]) |
| 1912 | updated = connection.execute( |
| 1913 | """ |
| 1914 | UPDATE scans |
| 1915 | SET handoff_claimed_at = ?, handoff_claim_token = ?, updated_at = ? |
| 1916 | WHERE id = ? AND handoff_status = 'pending' |
| 1917 | AND ( |
| 1918 | handoff_claim_token IS NULL |
| 1919 | OR ( |
| 1920 | ? = 1 |
| 1921 | AND (handoff_claimed_at IS NULL OR handoff_claimed_at <= ?) |
| 1922 | ) |
| 1923 | ) |
| 1924 | """, |
| 1925 | ( |
| 1926 | timestamp, |
| 1927 | claim_token, |
| 1928 | timestamp, |
| 1929 | scan["id"], |
| 1930 | int(args.take_over_stale), |
| 1931 | stale_claim_before(), |
| 1932 | ), |
| 1933 | ) |
| 1934 | if updated.rowcount != 1: |
| 1935 | return workspace_state(connection, scan["workspace_id"]) |
| 1936 | return workspace_state(connection, scan["workspace_id"]) |
| 1937 | |
| 1938 | |
| 1939 | def release_handoff_delivery( |
no test coverage detected