prefect_census.syncs
Module containing tasks and flows for interacting with Census syncs.
Classes
CensusSync
Bases: JobBlock
A Job Block for triggering a Census sync run and waiting for completion.
Attributes:
Name | Type | Description |
---|---|---|
credentials |
CensusCredentials
|
Credentials for authenticating with Census. |
sync_id |
int
|
The ID of the sync to trigger. |
force_full_sync |
bool
|
If |
max_wait_seconds |
int
|
Maximum number of seconds to wait for sync to complete. |
poll_frequency_seconds |
int
|
Number of seconds to wait in between checks for run completion. |
Example
Trigger a Census sync and wait for completion as a subflow:
from prefect import flow
from prefect_census import CensusSync, run_census_sync
@flow
def my_census_flow():
census_sync = CensusSync.load("BLOCK_NAME")
# do some setup
run_census_sync(census_sync)
# do some cleanup
Source code in prefect_census/syncs.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
Functions
trigger
async
Trigger a Census sync run.
Returns:
Type | Description |
---|---|
CensusSyncRun
|
A CensusSyncRun instance representing the triggered sync run. |
Source code in prefect_census/syncs.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
CensusSyncResult
Bases: BaseModel
The results for a Census Sync Run.
Source code in prefect_census/syncs.py
32 33 34 35 36 |
|
CensusSyncRun
Bases: JobRun
A Job Run representing a Census sync run.
Attributes:
Name | Type | Description |
---|---|---|
sync |
The CensusSync instance that triggered this run. |
|
run_id |
The ID of the Census sync run. |
|
run_data |
The data returned by the Census API for this run. |
|
status |
The status of the Census sync run. |
Source code in prefect_census/syncs.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
Functions
fetch_result
async
Fetch the result of the Census sync run.
Returns:
Type | Description |
---|---|
CensusSyncResult
|
A CensusSyncResult instance representing the result of the sync run. |
Source code in prefect_census/syncs.py
392 393 394 395 396 397 398 399 400 401 402 |
|
wait_for_completion
async
Wait for the Census sync run to complete.
Source code in prefect_census/syncs.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
CensusSyncTriggerFailed
Bases: RuntimeError
Used to indicate sync triggered.
Source code in prefect_census/syncs.py
28 29 |
|
Functions
trigger_census_sync
async
A task to trigger a Census sync run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
credentials |
CensusCredentials
|
Credentials for authenticating with Census. |
required |
sync_id |
int
|
The ID of the sync to trigger. |
required |
force_full_sync |
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
int
|
The ID of the triggered sync run. |
Examples:
Trigger a Census sync run:
from prefect import flow
from prefect_census import CensusCredentials
from prefect_census.syncs import trigger_census_sync
@flow
def trigger_census_sync_flow():
credentials = CensusCredentials(api_key="my_api_key")
trigger_census_sync(credentials=credentials, sync_id=42)
trigger_census_sync_flow()
Source code in prefect_census/syncs.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
trigger_census_sync_run_and_wait_for_completion
async
Flow that triggers a sync run and waits for the triggered run to complete.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
credentials |
CensusCredentials
|
Credentials for authenticating with Census. |
required |
sync_id |
int
|
The ID of the sync to trigger. |
required |
force_full_sync |
bool
|
If |
False
|
max_wait_seconds |
int
|
Maximum number of seconds to wait for sync to complete |
900
|
poll_frequency_seconds |
int
|
Number of seconds to wait in between checks for run completion. |
10
|
Raises:
Type | Description |
---|---|
CensusSyncRunCancelled
|
The triggered Census sync run was cancelled. |
CensusSyncRunFailed
|
The triggered Census sync run failed. |
RuntimeError
|
The triggered Census sync run ended in an unexpected state. |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
The final run data returned by the Census API as dict with the following shape:
|
Examples:
Trigger a Census sync using CensusCredentials instance and wait for completion as a standalone flow:
import asyncio
from prefect_census import CensusCredentials
from prefect_census.syncs import trigger_census_sync_run_and_wait_for_completion
asyncio.run(
trigger_census_sync_run_and_wait_for_completion(
credentials=CensusCredentials(
api_key="my_api_key"
),
sync_id=42
)
)
Trigger a Census sync and wait for completion as a subflow:
from prefect import flow
from prefect_census import CensusCredentials
from prefect_census.syncs import trigger_census_sync_run_and_wait_for_completion
@flow
def my_flow():
...
creds = CensusCredentials(api_key="my_api_key")
run_result = trigger_census_sync_run_and_wait_for_completion(
credentials=creds,
sync_id=42
)
...
my_flow()
Source code in prefect_census/syncs.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|