-
Notifications
You must be signed in to change notification settings - Fork 15
feat: Better Actor API typing #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91dd5e7
Introduce Webhook model
janbuchar eb4284b
Add ActorRun model
janbuchar 45226a6
Fix remaining return types
janbuchar 7caed86
Update unit tests
janbuchar 3c491af
Adjust ActorRun model so that we actually pass integration tests
janbuchar 38c685c
Merge remote-tracking branch 'origin/master' into better-actor-api-ty…
janbuchar 63e666d
Update upgrading guide
janbuchar 2e92adb
Apply suggestions from code review
janbuchar dde7fc2
More intermediate variables
janbuchar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
from importlib import metadata | ||
|
||
from apify_shared.consts import WebhookEventType | ||
from crawlee.events._types import Event | ||
|
||
from apify._actor import Actor | ||
from apify._configuration import Configuration | ||
from apify._models import Webhook | ||
from apify._proxy_configuration import ProxyConfiguration, ProxyInfo | ||
|
||
__version__ = metadata.version('apify') | ||
|
||
__all__ = ['Actor', 'Event', 'Configuration', 'ProxyConfiguration', 'ProxyInfo', '__version__'] | ||
__all__ = [ | ||
'Actor', | ||
'Event', | ||
'Configuration', | ||
'ProxyConfiguration', | ||
'ProxyInfo', | ||
'Webhook', | ||
'WebhookEventType', | ||
'__version__', | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# ruff: noqa: TCH001 TCH002 TCH003 (Pydantic) | ||
from __future__ import annotations | ||
|
||
from datetime import datetime, timedelta | ||
from typing import Annotated | ||
|
||
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field | ||
|
||
from apify_shared.consts import ActorJobStatus, MetaOrigin, WebhookEventType | ||
from crawlee._utils.models import timedelta_ms | ||
from crawlee._utils.urls import validate_http_url | ||
|
||
|
||
class Webhook(BaseModel): | ||
__model_config__ = ConfigDict(populate_by_name=True) | ||
|
||
event_types: Annotated[ | ||
list[WebhookEventType], | ||
Field(description='Event types that should trigger the webhook'), | ||
] | ||
request_url: Annotated[ | ||
str, | ||
Field(description='URL that the webhook should call'), | ||
BeforeValidator(validate_http_url), | ||
] | ||
payload_template: Annotated[ | ||
str | None, | ||
Field(description='Template for the payload sent by the webook'), | ||
] = None | ||
|
||
|
||
class ActorRunMeta(BaseModel): | ||
__model_config__ = ConfigDict(populate_by_name=True) | ||
|
||
origin: Annotated[MetaOrigin, Field()] | ||
|
||
|
||
class ActorRunStats(BaseModel): | ||
__model_config__ = ConfigDict(populate_by_name=True) | ||
|
||
input_body_len: Annotated[int, Field(alias='inputBodyLen')] | ||
restart_count: Annotated[int, Field(alias='restartCount')] | ||
resurrect_count: Annotated[int, Field(alias='resurrectCount')] | ||
mem_avg_bytes: Annotated[float | None, Field(alias='memAvgBytes')] = None | ||
mem_max_bytes: Annotated[int | None, Field(alias='memMaxBytes')] = None | ||
mem_current_bytes: Annotated[int | None, Field(alias='memCurrentBytes')] = None | ||
cpu_avg_usage: Annotated[float | None, Field(alias='cpuAvgUsage')] = None | ||
cpu_max_usage: Annotated[float | None, Field(alias='cpuMaxUsage')] = None | ||
cpu_current_usage: Annotated[float | None, Field(alias='cpuCurrentUsage')] = None | ||
net_rx_bytes: Annotated[int | None, Field(alias='netRxBytes')] = None | ||
net_tx_bytes: Annotated[int | None, Field(alias='netTxBytes')] = None | ||
duration: Annotated[timedelta_ms | None, Field(alias='durationMillis')] = None | ||
run_time: Annotated[timedelta | None, Field(alias='runTimeSecs')] = None | ||
metamorph: Annotated[int | None, Field(alias='metamorph')] = None | ||
compute_units: Annotated[float, Field(alias='computeUnits')] | ||
|
||
|
||
class ActorRunOptions(BaseModel): | ||
__model_config__ = ConfigDict(populate_by_name=True) | ||
build: str | ||
janbuchar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
timeout: Annotated[timedelta, Field(alias='timeoutSecs')] | ||
memory_mbytes: Annotated[int, Field(alias='memoryMbytes')] | ||
disk_mbytes: Annotated[int, Field(alias='diskMbytes')] | ||
|
||
|
||
class ActorRunUsage(BaseModel): | ||
__model_config__ = ConfigDict(populate_by_name=True) | ||
actor_compute_units: Annotated[float | None, Field(alias='ACTOR_COMPUTE_UNITS')] = None | ||
janbuchar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dataset_reads: Annotated[float | None, Field(alias='DATASET_READS')] = None | ||
dataset_writes: Annotated[float | None, Field(alias='DATASET_WRITES')] = None | ||
key_value_store_reads: Annotated[float | None, Field(alias='KEY_VALUE_STORE_READS')] = None | ||
key_value_store_writes: Annotated[float | None, Field(alias='KEY_VALUE_STORE_WRITES')] = None | ||
key_value_store_lists: Annotated[float | None, Field(alias='KEY_VALUE_STORE_LISTS')] = None | ||
request_queue_reads: Annotated[float | None, Field(alias='REQUEST_QUEUE_READS')] = None | ||
request_queue_writes: Annotated[float | None, Field(alias='REQUEST_QUEUE_WRITES')] = None | ||
data_transfer_internal_gbytes: Annotated[float | None, Field(alias='DATA_TRANSFER_INTERNAL_GBYTES')] = None | ||
data_transfer_external_gbytes: Annotated[float | None, Field(alias='DATA_TRANSFER_EXTERNAL_GBYTES')] = None | ||
proxy_residential_transfer_gbytes: Annotated[float | None, Field(alias='PROXY_RESIDENTIAL_TRANSFER_GBYTES')] = None | ||
proxy_serps: Annotated[float | None, Field(alias='PROXY_SERPS')] = None | ||
|
||
|
||
class ActorRun(BaseModel): | ||
__model_config__ = ConfigDict(populate_by_name=True) | ||
|
||
id: Annotated[str, Field(alias='id')] | ||
act_id: Annotated[str, Field(alias='actId')] | ||
user_id: Annotated[str, Field(alias='userId')] | ||
actor_task_id: Annotated[str | None, Field(alias='actorTaskId')] = None | ||
started_at: Annotated[datetime, Field(alias='startedAt')] | ||
finished_at: Annotated[datetime | None, Field(alias='finishedAt')] = None | ||
status: Annotated[ActorJobStatus, Field(alias='status')] | ||
status_message: Annotated[str | None, Field(alias='statusMessage')] = None | ||
is_status_message_terminal: Annotated[bool | None, Field(alias='isStatusMessageTerminal')] = None | ||
meta: Annotated[ActorRunMeta, Field(alias='meta')] | ||
stats: Annotated[ActorRunStats, Field(alias='stats')] | ||
options: Annotated[ActorRunOptions, Field(alias='options')] | ||
build_id: Annotated[str, Field(alias='buildId')] | ||
exit_code: Annotated[int | None, Field(alias='exitCode')] = None | ||
default_key_value_store_id: Annotated[str, Field(alias='defaultKeyValueStoreId')] | ||
default_dataset_id: Annotated[str, Field(alias='defaultDatasetId')] | ||
default_request_queue_id: Annotated[str, Field(alias='defaultRequestQueueId')] | ||
build_number: Annotated[str | None, Field(alias='buildNumber')] = None | ||
container_url: Annotated[str, Field(alias='containerUrl')] | ||
is_container_server_ready: Annotated[bool | None, Field(alias='isContainerServerReady')] = None | ||
git_branch_name: Annotated[str | None, Field(alias='gitBranchName')] = None | ||
usage: Annotated[ActorRunUsage | None, Field(alias='usage')] = None | ||
usage_total_usd: Annotated[float | None, Field(alias='usageTotalUsd')] = None | ||
usage_usd: Annotated[ActorRunUsage | None, Field(alias='usageUsd')] = None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.