Skip to content

Commit e324430

Browse files
author
stlc-bot
committed
feat(batch): accept lightweight submissions and queue pending work (#2683)
Stainless-Generated-From: 969f36bcbf28ac9d5facfc2af1f709b5ca5b9069
1 parent ae1a238 commit e324430

13 files changed

Lines changed: 39 additions & 21 deletions

File tree

‎src/Batch/BatchGetResponse.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ final class BatchGetResponse implements BaseModel
136136
public ?Results $results;
137137

138138
/**
139-
* Current state. `completed`, `cancelled`, and `failed` are final.
139+
* Current state. `pending` means waiting for execution capacity or background validation. Capacity-limited batches remain pending until a slot opens. `completed`, `cancelled`, and `failed` are final.
140140
*
141141
* @var value-of<Status> $status
142142
*/
@@ -443,7 +443,7 @@ public function withResults(Results|array|null $results): self
443443
}
444444

445445
/**
446-
* Current state. `completed`, `cancelled`, and `failed` are final.
446+
* Current state. `pending` means waiting for execution capacity or background validation. Capacity-limited batches remain pending until a slot opens. `completed`, `cancelled`, and `failed` are final.
447447
*
448448
* @param Status|value-of<Status> $status
449449
*/

‎src/Batch/BatchGetResponse/Credits.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class Credits implements BaseModel
3939
public int $refunded;
4040

4141
/**
42-
* Credits held when the batch was accepted.
42+
* Credits held by background preparation before scraping starts. Zero while pending.
4343
*/
4444
#[Required]
4545
public int $reserved;
@@ -122,7 +122,7 @@ public function withRefunded(int $refunded): self
122122
}
123123

124124
/**
125-
* Credits held when the batch was accepted.
125+
* Credits held by background preparation before scraping starts. Zero while pending.
126126
*/
127127
public function withReserved(int $reserved): self
128128
{

‎src/Batch/BatchGetResponse/Status.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
namespace ContextDev\Batch\BatchGetResponse;
66

77
/**
8-
* Current state. `completed`, `cancelled`, and `failed` are final.
8+
* Current state. `pending` means waiting for execution capacity or background validation. Capacity-limited batches remain pending until a slot opens. `completed`, `cancelled`, and `failed` are final.
99
*/
1010
enum Status: string
1111
{
12+
case PENDING = 'pending';
13+
1214
case QUEUED = 'queued';
1315

1416
case RUNNING = 'running';

‎src/Batch/BatchListParams/Status.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
enum Status: string
1111
{
12+
case PENDING = 'pending';
13+
1214
case QUEUED = 'queued';
1315

1416
case RUNNING = 'running';

‎src/Batch/BatchListResponse/Data.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ final class Data implements BaseModel
120120
public ?Results $results;
121121

122122
/**
123-
* Current state. `completed`, `cancelled`, and `failed` are final.
123+
* Current state. `pending` means waiting for execution capacity or background validation. Capacity-limited batches remain pending until a slot opens. `completed`, `cancelled`, and `failed` are final.
124124
*
125125
* @var value-of<Status> $status
126126
*/
@@ -377,7 +377,7 @@ public function withResults(Results|array|null $results): self
377377
}
378378

379379
/**
380-
* Current state. `completed`, `cancelled`, and `failed` are final.
380+
* Current state. `pending` means waiting for execution capacity or background validation. Capacity-limited batches remain pending until a slot opens. `completed`, `cancelled`, and `failed` are final.
381381
*
382382
* @param Status|value-of<Status> $status
383383
*/

‎src/Batch/BatchListResponse/Data/Credits.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class Credits implements BaseModel
3939
public int $refunded;
4040

4141
/**
42-
* Credits held when the batch was accepted.
42+
* Credits held by background preparation before scraping starts. Zero while pending.
4343
*/
4444
#[Required]
4545
public int $reserved;
@@ -122,7 +122,7 @@ public function withRefunded(int $refunded): self
122122
}
123123

124124
/**
125-
* Credits held when the batch was accepted.
125+
* Credits held by background preparation before scraping starts. Zero while pending.
126126
*/
127127
public function withReserved(int $reserved): self
128128
{

‎src/Batch/BatchListResponse/Data/Status.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
namespace ContextDev\Batch\BatchListResponse\Data;
66

77
/**
8-
* Current state. `completed`, `cancelled`, and `failed` are final.
8+
* Current state. `pending` means waiting for execution capacity or background validation. Capacity-limited batches remain pending until a slot opens. `completed`, `cancelled`, and `failed` are final.
99
*/
1010
enum Status: string
1111
{
12+
case PENDING = 'pending';
13+
1214
case QUEUED = 'queued';
1315

1416
case RUNNING = 'running';

‎src/Batch/BatchSubmitParams.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use ContextDev\Core\Contracts\BaseModel;
1616

1717
/**
18-
* Scrape up to 100,000 URLs, or crawl a site, asynchronously using the same formats and scrape parameters as POST /web/scrape. Choose Markdown, HTML, screenshots, images, bytes, parsed fields, products, highlights, and JSON. Poll the batch ID or receive a webhook when it finishes.
18+
* Scrape up to 100,000 URLs, or crawl a site, asynchronously using the same formats and scrape parameters as POST /web/scrape. Choose Markdown, HTML, screenshots, images, bytes, parsed fields, products, highlights, and JSON. Submission persists the input and returns immediately with status pending. Organizations with fewer than 10 available credits and no overage are rejected with 402 up front. Each organization can submit up to 1,000 batches per minute, independently of its polling budget. Batches wait pending when execution capacity is full. Validation, sitemap discovery, the full credit quote, and shard scheduling happen afterward. Poll the batch ID or receive a webhook when it finishes. Deferred rejections appear as status failed with a failure code and message.
1919
*
2020
* @see ContextDev\Services\BatchService::submit()
2121
*

‎src/Batch/BatchSubmitResponse.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ final class BatchSubmitResponse implements BaseModel
7272
public string $createdAt;
7373

7474
/**
75-
* What accepting this batch cost.
75+
* Credits are reserved after background validation, before scraping starts.
7676
*/
7777
#[Required]
7878
public Credits $credits;
@@ -112,7 +112,7 @@ final class BatchSubmitResponse implements BaseModel
112112
public string $requestID;
113113

114114
/**
115-
* Always `queued`. An accepted batch has not started yet.
115+
* Current state. `pending` means waiting for execution capacity or background validation. Capacity-limited batches remain pending until a slot opens. `completed`, `cancelled`, and `failed` are final.
116116
*
117117
* @var value-of<Status> $status
118118
*/
@@ -285,7 +285,7 @@ public function withCreatedAt(string $createdAt): self
285285
}
286286

287287
/**
288-
* What accepting this batch cost.
288+
* Credits are reserved after background validation, before scraping starts.
289289
*
290290
* @param Credits|CreditsShape $credits
291291
*/
@@ -361,7 +361,7 @@ public function withRequestID(string $requestID): self
361361
}
362362

363363
/**
364-
* Always `queued`. An accepted batch has not started yet.
364+
* Current state. `pending` means waiting for execution capacity or background validation. Capacity-limited batches remain pending until a slot opens. `completed`, `cancelled`, and `failed` are final.
365365
*
366366
* @param Status|value-of<Status> $status
367367
*/

‎src/Batch/BatchSubmitResponse/Credits.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use ContextDev\Core\Contracts\BaseModel;
1010

1111
/**
12-
* What accepting this batch cost.
12+
* Credits are reserved after background validation, before scraping starts.
1313
*
1414
* @phpstan-type CreditsShape = array{reserved: int}
1515
*/
@@ -19,7 +19,7 @@ final class Credits implements BaseModel
1919
use SdkModel;
2020

2121
/**
22-
* Credits held at submission.
22+
* Credits reserved by background preparation. Zero while pending.
2323
*/
2424
#[Required]
2525
public int $reserved;
@@ -58,7 +58,7 @@ public static function with(int $reserved): self
5858
}
5959

6060
/**
61-
* Credits held at submission.
61+
* Credits reserved by background preparation. Zero while pending.
6262
*/
6363
public function withReserved(int $reserved): self
6464
{

0 commit comments

Comments
 (0)