Index
Task scheduling functionality for Home Assistant automations.
This module provides clean access to the scheduler system for running jobs at specific times, intervals, or based on cron expressions.
TriggerProtocol
Bases: Protocol
Protocol for defining triggers.
Six methods make up the contract: - first_run_time: returns the first scheduled run time given the current time - next_run_time: returns the next run time after a previous run, or None for one-shot triggers - trigger_label: short stable label for telemetry / UI display - trigger_detail: optional human-readable detail string - trigger_db_type: canonical type string for database storage - trigger_id: stable string identifier used for deduplication
Source code in src/hassette/types/types.py
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 | |
first_run_time(current_time: ZonedDateTime) -> ZonedDateTime
Return the first scheduled run time at or after current_time.
Source code in src/hassette/types/types.py
190 191 192 | |
next_run_time(previous_run: ZonedDateTime, current_time: ZonedDateTime) -> ZonedDateTime | None
Return the next run time after previous_run, or None for one-shot triggers.
Source code in src/hassette/types/types.py
194 195 196 | |
trigger_label() -> str
Human-readable display label for the UI.
Custom triggers (those returning "custom" from trigger_db_type())
MUST NOT return one of the built-in reserved names ("after",
"once", "every", "daily", "cron") from this method.
Doing so creates misleading telemetry and UI rows where the
trigger_type column is "custom" but the label implies a
built-in trigger kind.
Source code in src/hassette/types/types.py
198 199 200 201 202 203 204 205 206 207 208 | |
trigger_detail() -> str | None
Optional human-readable detail string.
Source code in src/hassette/types/types.py
210 211 212 | |
trigger_db_type() -> Literal['interval', 'cron', 'once', 'after', 'custom']
Canonical type string for database storage.
Source code in src/hassette/types/types.py
214 215 216 | |
trigger_id() -> str
Stable string identifier used for deduplication.
Source code in src/hassette/types/types.py
218 219 220 | |
ScheduledJob
dataclass
A job scheduled to run based on a trigger or at a specific time.
Source code in src/hassette/scheduler/classes.py
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 227 228 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 320 321 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 403 404 405 406 407 | |
sort_index: tuple[int, int] = field(init=False, repr=False)
class-attribute
instance-attribute
Tuple of (next_run timestamp with nanoseconds, object id) for ordering in a priority queue.
owner_id: str = field(compare=False)
class-attribute
instance-attribute
Unique string identifier for the owner of the job, e.g., a component or integration name.
next_run: ZonedDateTime = field(compare=False)
class-attribute
instance-attribute
Unjittered logical fire time — used as previous_run in subsequent trigger calls.
fire_at: ZonedDateTime = field(init=False, compare=False)
class-attribute
instance-attribute
Actual dispatch time, including any jitter offset.
Equals next_run when no jitter is configured. Set by
SchedulerService.apply_jitter_to_heap() at enqueue time when jitter > 0.
The pop loop in _ScheduledJobQueue.pop_due_and_peek_next compares against
fire_at (not next_run) to decide when to dispatch.
job: JobCallable = field(compare=False)
class-attribute
instance-attribute
The callable to execute when the job runs.
app_key: str = field(default='', compare=False)
class-attribute
instance-attribute
Configuration-level app key for DB registration (e.g., 'my_app'). Empty for non-App owners.
instance_index: int = field(default=0, compare=False)
class-attribute
instance-attribute
App instance index for DB registration. 0 for non-App owners.
instance_name: str | None = field(default=None, compare=False)
class-attribute
instance-attribute
App instance name, precomputed at registration time from the owning app's app_config.instance_name. None for framework-tier jobs and non-App owners.
trigger: TriggerProtocol | None = field(compare=False, default=None)
class-attribute
instance-attribute
The trigger that determines the job's schedule.
group: str | None = field(default=None, compare=False)
class-attribute
instance-attribute
Optional group name for grouping related jobs. Included in deduplication comparison.
jitter: float | None = field(default=None, compare=False)
class-attribute
instance-attribute
Seconds of random offset applied at enqueue time by SchedulerService.apply_jitter_to_heap().
Does not affect next_run (unjittered logical fire time). See the fire_at field on
ScheduledJob for the actual dispatch time after jitter is applied.
timeout: float | None = field(default=None, compare=False)
class-attribute
instance-attribute
Per-job timeout in seconds. None means use the global default
(config.scheduler_job_timeout_seconds). A positive float overrides the default.
Validated at construction: must be positive when set.
timeout_disabled: bool = field(default=False, compare=False)
class-attribute
instance-attribute
When True, timeout enforcement is disabled for this job regardless of the global default.
name: str = field(default='', compare=False)
class-attribute
instance-attribute
Name for the job, used for identification. Required by all public Scheduler entry points
(Scheduler.add_job() and Scheduler.schedule() raise SchedulerNameRequiredError if empty).
args: tuple[Any, ...] = field(default_factory=tuple, compare=False)
class-attribute
instance-attribute
Positional arguments to pass to the job callable.
kwargs: dict[str, Any] = field(default_factory=dict, compare=False)
class-attribute
instance-attribute
Keyword arguments to pass to the job callable.
error_handler: SchedulerErrorHandlerType | None = field(default=None, compare=False)
class-attribute
instance-attribute
Optional error handler for this job.
When set, this handler is invoked if the job raises an exception (including
TimeoutError, but excluding CancelledError). Stored as-is for identity comparison
in matches(). compare=False prevents Callable | None from corrupting
the @dataclass(order=True) heap ordering.
db_id: int | None = field(default=None, compare=False)
class-attribute
instance-attribute
Database row ID for this job. Set by the executor after persistence; None until then.
source_location: str = field(default='', compare=False)
class-attribute
instance-attribute
Captured source location (file:line) of the user code that scheduled this job.
registration_source: str = field(default='', compare=False)
class-attribute
instance-attribute
Captured source code snippet of the scheduling call.
source_tier: SourceTier = field(default='app', compare=False)
class-attribute
instance-attribute
Whether this job originates from a user app or the framework itself.
mode: ExecutionMode = field(default=(ExecutionMode.SINGLE), compare=False)
class-attribute
instance-attribute
Resolved overlap mode for this job. Determines behavior when a prior invocation is still
running as the next occurrence becomes due. Defaults to ExecutionMode.SINGLE so existing
direct ScheduledJob(...) constructions in tests remain valid; the real resolution happens
in Scheduler.schedule().
predicate: SchedulerPredicate | None = field(default=None, compare=False)
class-attribute
instance-attribute
Normalized predicate callable, or None when no where= was given.
Set once at registration time by Scheduler.schedule() — a single callable is stored
directly, and a sequence of predicates is collapsed into a combinator. compare=False
prevents Callable | None from corrupting the @dataclass(order=True) heap ordering.
predicate_invoker: CallableInvoker | None = field(default=None, repr=False, compare=False)
class-attribute
instance-attribute
Pre-built DI invoker for the predicate, or None when no where= was given.
Built once at registration time by Scheduler.schedule() using the shared DI layer
(hassette.di) and passed alongside predicate. At dispatch time,
predicate_invoker.invoke({ScheduledJob: job}) produces kwargs and the predicate is
called with predicate(**kwargs).
guard: ExecutionModeGuard = field(init=False, compare=False)
class-attribute
instance-attribute
Per-job overlap state machine. Created in __post_init__ from mode. Lives for the
full lifetime of the job, spanning all re-fires. compare=False prevents the guard from
affecting heap ordering. init=False — do not pass directly; set via mode.
app_error_handler_resolver: Callable[[], SchedulerErrorHandlerType | None] | None = field(default=None, init=False, repr=False)
class-attribute
instance-attribute
Closure that resolves the app-level error handler at dispatch time.
pending_done: set[asyncio.Future[None]] = field(default_factory=set, init=False, repr=False, compare=False)
class-attribute
instance-attribute
Unresolved per-invocation completion futures for non-parallel modes.
Each run_job_with_guard call for single/restart/queued parks the outer dispatch task on
a future that resolves when the invocation actually runs (or is dropped/released). A queued
invocation accepted into the guard deque has no live child until drain time, so its future
would hang forever if the job is cancelled first. dequeue_job, _remove_job, and
_remove_jobs_by_owner call drain_pending_done(job.pending_done) after
guard.release() so those dispatch tasks unwind.
mark_registered(db_id: int) -> None
Set the database ID. Called by SchedulerService.add_job() after persistence.
First call wins — a second call keeps the original id and logs a WARNING so a
retry or double-registration is surfaced rather than silently swallowed.
Mirrors Listener.mark_registered.
Source code in src/hassette/scheduler/classes.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
matches(other: ScheduledJob) -> bool
Check whether two jobs represent the same logical configuration.
Compares callable, trigger (by trigger_id()), group, jitter, timeout, timeout_disabled, args, kwargs, error_handler (by identity), mode, and predicate (by equality — lambdas/closures compare by identity). Does not compare runtime state (db_id, next_run, sort_index, _scheduler, _dequeued, owner, or any other mutable runtime field).
Two jobs with identical callable/trigger/args but different groups are distinct logical jobs and will not match.
Source code in src/hassette/scheduler/classes.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
diff_fields(other: ScheduledJob) -> list[str]
Return a list of configuration field names that differ between two jobs.
Compares the same fields as matches() — callable, trigger, group,
jitter, timeout, timeout_disabled, args, kwargs, error_handler, mode,
and predicate.
Source code in src/hassette/scheduler/classes.py
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 | |
set_app_error_handler_resolver(resolver: Callable[[], SchedulerErrorHandlerType | None]) -> None
Set the closure that resolves the app-level error handler at dispatch time.
Source code in src/hassette/scheduler/classes.py
379 380 381 | |
cancel() -> None
Cancel the job by delegating to the owning Scheduler.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When called on a job that has not been registered with a Scheduler.
Use |
Source code in src/hassette/scheduler/classes.py
383 384 385 386 387 388 389 390 391 392 393 394 395 | |
set_next_run(next_run: ZonedDateTime) -> None
Update the next run timestamp, fire_at, and ordering metadata.
Both next_run and fire_at are set to the rounded value. Call
SchedulerService.apply_jitter_to_heap() after this to set a jittered
fire_at when the job has jitter configured.
Source code in src/hassette/scheduler/classes.py
397 398 399 400 401 402 403 404 405 406 407 | |
SchedulerErrorContext
dataclass
Bases: ErrorContext
Context passed to scheduler error handlers when a job raises an exception.
Attributes:
| Name | Type | Description |
|---|---|---|
exception |
BaseException
|
The exception that was raised by the job. |
traceback |
str
|
Formatted traceback string. |
job_name |
str
|
The name of the job function that raised the exception. |
job_group |
str | None
|
The group the job belongs to, or None if ungrouped. |
args |
tuple[Any, ...]
|
Positional arguments the job was scheduled with. |
kwargs |
dict[str, Any]
|
Keyword arguments the job was scheduled with. |
Source code in src/hassette/scheduler/error_context.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
Scheduler
Bases: Resource
Scheduler resource for managing scheduled jobs.
Source code in src/hassette/scheduler/scheduler.py
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 227 228 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 320 321 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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 | |
scheduler_service: SchedulerServiceProtocol = self.hassette.scheduler_service
instance-attribute
The scheduler service instance.
sync: SchedulerSyncFacade = self.add_child(SchedulerSyncFacade, scheduler=self)
instance-attribute
Synchronous facade for scheduling jobs from sync code (e.g. AppSync hooks).
config_log_level: LOG_LEVEL_TYPE
property
Return the log level from the config for this resource.
on_error(handler: SchedulerErrorHandlerType) -> None
Register an app-level error handler for this scheduler.
The handler is called when any job on this scheduler raises an exception
(including TimeoutError) and the job does not have its own
per-registration error handler.
This is an app-level fallback — it is resolved at dispatch time, not at job
registration time. A later call to on_error() replaces any previously
registered handler.
Note: error handlers are spawned as fire-and-forget tasks. Handlers spawned near app shutdown may be cancelled before they complete. Do not rely on error handlers for delivery-critical alerting during system teardown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
SchedulerErrorHandlerType
|
A sync or async callable that accepts a
:class: |
required |
Source code in src/hassette/scheduler/scheduler.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
add_job(job: ScheduledJob, *, if_exists: IfExistsPolicy = 'error') -> Coroutine[Any, Any, ScheduledJob]
Add a job to the scheduler.
Must be awaited. Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
DB registration is awaited inline — job.db_id is set before this
method returns, eliminating the window where a job fires with
db_id=None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
ScheduledJob
|
The job to add. |
required |
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
|
'error'
|
Returns:
| Type | Description |
|---|---|
Coroutine[Any, Any, ScheduledJob]
|
The added job, or the existing job when |
Coroutine[Any, Any, ScheduledJob]
|
matching job is already registered. |
Coroutine[Any, Any, ScheduledJob]
|
integer immediately on return. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If job is not a ScheduledJob. |
SchedulerNameRequiredError
|
If |
ValueError
|
If a job with the same name already exists and either
|
Source code in src/hassette/scheduler/scheduler.py
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 227 228 229 230 231 232 233 234 235 | |
cancel_job(job: ScheduledJob) -> None
Cancel an individual job and persist the cancellation to the database.
Idempotent: a second cancel on the same job is a silent no-op. Raises
ValueError if the job belongs to a different scheduler instance.
Spawns a durable mark_job_cancelled DB write (when db_id is set),
dequeues the job from the service, and sets job._dequeued = True.
Must NOT call job.cancel() internally — that delegates back here and
would cause infinite recursion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
ScheduledJob
|
The job to cancel. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the job belongs to a different scheduler instance. |
Source code in src/hassette/scheduler/scheduler.py
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 320 321 322 | |
cancel_group(group: str) -> None
Cancel all jobs in the given group.
Delegates to cancel_job per-member, which handles the DB write,
dequeue, and _dequeued flag. Dict cleanup (_jobs_by_group and
_jobs_by_name) is handled by the _on_job_removed callback
fired by scheduler_service.dequeue_job. No-op if the group does
not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str
|
The group name to cancel. |
required |
Source code in src/hassette/scheduler/scheduler.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
list_jobs(group: str | None = None) -> list[ScheduledJob]
Return all or group-filtered jobs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str | None
|
If provided, return only jobs in this group.
If |
None
|
Returns:
| Type | Description |
|---|---|
list[ScheduledJob]
|
List of ScheduledJob instances. |
Source code in src/hassette/scheduler/scheduler.py
346 347 348 349 350 351 352 353 354 355 356 357 358 | |
get_job_db_ids() -> list[int]
Return the DB IDs of all registered jobs.
Used by post-ready reconciliation in AppLifecycleService.initialize_instances()
to build the live_job_ids set. With synchronous registration, all jobs
have a db_id set by the time on_initialize completes. The
db_id is not None guard is kept as a defensive filter.
Returns:
| Type | Description |
|---|---|
list[int]
|
List of integer DB row IDs for registered jobs. |
Source code in src/hassette/scheduler/scheduler.py
360 361 362 363 364 365 366 367 368 369 370 371 | |
schedule(func: JobCallable, trigger: TriggerProtocol, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> Coroutine[Any, Any, ScheduledJob]
Schedule a job using a trigger object.
Must be awaited. Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
This is the primary entry point for scheduling. All convenience methods
(run_in, run_every, run_daily, etc.) delegate here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
trigger
|
TriggerProtocol
|
A trigger object implementing |
required |
name
|
str
|
Required stable name for the job. Used for uniqueness validation within this scheduler instance and for logging/telemetry. |
required |
group
|
str | None
|
Optional group name for bulk management (see |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
Jitter is applied via |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. |
None
|
timeout_disabled
|
bool
|
When |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
occurrence becomes due. One of |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. When set, this handler is
invoked if the job raises an exception (including |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) evaluated at dispatch
time, before the handler runs. Predicate signatures are inspected via
the shared DI layer ( |
None
|
Returns:
| Type | Description |
|---|---|
Coroutine[Any, Any, ScheduledJob]
|
The scheduled job. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
SchedulerNameRequiredError
|
If |
DependencyInjectionError
|
If a predicate's signature is incompatible with
DI (e.g. |
Source code in src/hassette/scheduler/scheduler.py
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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | |
run_in(func: JobCallable, delay: float, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> Coroutine[Any, Any, ScheduledJob]
Schedule a job to run after a fixed delay (one-shot).
Must be awaited. Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
delay
|
float
|
The delay in seconds before running the job. |
required |
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap mode. Accepted for API uniformity; has no overlap effect for
one-shot jobs since they never re-fire. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
Coroutine[Any, Any, ScheduledJob]
|
The scheduled job. |
Source code in src/hassette/scheduler/scheduler.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | |
run_once(func: JobCallable, at: str | ZonedDateTime, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, if_past: Literal['tomorrow', 'error'] = 'tomorrow', mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> Coroutine[Any, Any, ScheduledJob]
Schedule a job to run once at a specific wall-clock time (one-shot).
Must be awaited. Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
at
|
str | ZonedDateTime
|
Target time. A |
required |
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
if_past
|
Literal['tomorrow', 'error']
|
Behaviour when the target time is in the past at construction
time. |
'tomorrow'
|
mode
|
ExecutionMode | str | None
|
Overlap mode. Accepted for API uniformity; has no overlap effect for
one-shot jobs since they never re-fire. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
Coroutine[Any, Any, ScheduledJob]
|
The scheduled job. |
Source code in src/hassette/scheduler/scheduler.py
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | |
run_every(func: JobCallable, hours: float = 0, minutes: float = 0, seconds: float = 0, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> Coroutine[Any, Any, ScheduledJob]
Schedule a job to run at a fixed interval.
Must be awaited. Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
hours
|
float
|
Interval hours component. |
0
|
minutes
|
float
|
Interval minutes component. |
0
|
seconds
|
float
|
Interval seconds component. |
0
|
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
tick becomes due. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
Coroutine[Any, Any, ScheduledJob]
|
The scheduled job. |
Source code in src/hassette/scheduler/scheduler.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
run_minutely(func: JobCallable, minutes: int = 1, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> Coroutine[Any, Any, ScheduledJob]
Schedule a job to run every N minutes.
Must be awaited. Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
minutes
|
int
|
The minute interval (must be >= 1). |
1
|
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
tick becomes due. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
Coroutine[Any, Any, ScheduledJob]
|
The scheduled job. |
Source code in src/hassette/scheduler/scheduler.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |
run_hourly(func: JobCallable, hours: int = 1, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> Coroutine[Any, Any, ScheduledJob]
Schedule a job to run every N hours.
Must be awaited. Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
hours
|
int
|
The hour interval (must be >= 1). |
1
|
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
tick becomes due. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
Coroutine[Any, Any, ScheduledJob]
|
The scheduled job. |
Source code in src/hassette/scheduler/scheduler.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 | |
run_daily(func: JobCallable, at: str = '00:00', *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> Coroutine[Any, Any, ScheduledJob]
Schedule a job to run once per day at a fixed wall-clock time.
Must be awaited. Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Uses a cron-based trigger internally to ensure DST-correct, wall-clock-aligned scheduling. This avoids the 24-hour drift bug of interval-based daily scheduling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
at
|
str
|
Target wall-clock time in |
'00:00'
|
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
tick becomes due. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
Coroutine[Any, Any, ScheduledJob]
|
The scheduled job. |
Source code in src/hassette/scheduler/scheduler.py
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 | |
run_cron(func: JobCallable, expression: str, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> Coroutine[Any, Any, ScheduledJob]
Schedule a job using a cron expression.
Must be awaited. Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Accepts both 5-field (standard Unix cron: minute hour dom month dow)
and 6-field expressions (seconds appended as a 6th field per croniter
convention: minute hour dom month dow second).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
expression
|
str
|
A valid 5- or 6-field cron expression. |
required |
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
tick becomes due. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
Coroutine[Any, Any, ScheduledJob]
|
The scheduled job. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the cron expression is syntactically invalid. |
Source code in src/hassette/scheduler/scheduler.py
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 | |
SchedulerSyncFacade
Bases: Resource
Synchronous facade for the scheduler.
This class provides synchronous methods that wrap the asynchronous scheduling methods of
the Scheduler class, allowing jobs to be scheduled from synchronous code (for example, an
AppSync lifecycle hook running in a worker thread).
These methods must not be called from within the event loop; doing so raises a RuntimeError.
Use the asynchronous methods on Scheduler directly when operating within an event loop.
Source code in src/hassette/scheduler/sync.py
28 29 30 31 32 33 34 35 36 37 38 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 96 97 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 227 228 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 320 321 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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | |
add_job(job: ScheduledJob, *, if_exists: IfExistsPolicy = 'error') -> ScheduledJob
Add a job to the scheduler.
Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
DB registration completes inline — job.db_id is set before this
method returns, eliminating the window where a job fires with
db_id=None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
ScheduledJob
|
The job to add. |
required |
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
|
'error'
|
Returns:
| Type | Description |
|---|---|
ScheduledJob
|
The added job, or the existing job when |
ScheduledJob
|
matching job is already registered. |
ScheduledJob
|
integer immediately on return. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If job is not a ScheduledJob. |
SchedulerNameRequiredError
|
If |
ValueError
|
If a job with the same name already exists and either
|
Source code in src/hassette/scheduler/sync.py
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 | |
schedule(func: JobCallable, trigger: TriggerProtocol, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> ScheduledJob
Schedule a job using a trigger object.
Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
This is the primary entry point for scheduling. All convenience methods
(run_in, run_every, run_daily, etc.) delegate here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
trigger
|
TriggerProtocol
|
A trigger object implementing |
required |
name
|
str
|
Required stable name for the job. Used for uniqueness validation within this scheduler instance and for logging/telemetry. |
required |
group
|
str | None
|
Optional group name for bulk management (see |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
Jitter is applied via |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. |
None
|
timeout_disabled
|
bool
|
When |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
occurrence becomes due. One of |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. When set, this handler is
invoked if the job raises an exception (including |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) evaluated at dispatch
time, before the handler runs. Predicate signatures are inspected via
the shared DI layer ( |
None
|
Returns:
| Type | Description |
|---|---|
ScheduledJob
|
The scheduled job. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
SchedulerNameRequiredError
|
If |
DependencyInjectionError
|
If a predicate's signature is incompatible with
DI (e.g. |
Source code in src/hassette/scheduler/sync.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 | |
run_in(func: JobCallable, delay: float, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> ScheduledJob
Schedule a job to run after a fixed delay (one-shot).
Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
delay
|
float
|
The delay in seconds before running the job. |
required |
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap mode. Accepted for API uniformity; has no overlap effect for
one-shot jobs since they never re-fire. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
ScheduledJob
|
The scheduled job. |
Source code in src/hassette/scheduler/sync.py
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
run_once(func: JobCallable, at: str | ZonedDateTime, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, if_past: Literal['tomorrow', 'error'] = 'tomorrow', mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> ScheduledJob
Schedule a job to run once at a specific wall-clock time (one-shot).
Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
at
|
str | ZonedDateTime
|
Target time. A |
required |
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
if_past
|
Literal['tomorrow', 'error']
|
Behaviour when the target time is in the past at construction
time. |
'tomorrow'
|
mode
|
ExecutionMode | str | None
|
Overlap mode. Accepted for API uniformity; has no overlap effect for
one-shot jobs since they never re-fire. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
ScheduledJob
|
The scheduled job. |
Source code in src/hassette/scheduler/sync.py
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 | |
run_every(func: JobCallable, hours: float = 0, minutes: float = 0, seconds: float = 0, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> ScheduledJob
Schedule a job to run at a fixed interval.
Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
hours
|
float
|
Interval hours component. |
0
|
minutes
|
float
|
Interval minutes component. |
0
|
seconds
|
float
|
Interval seconds component. |
0
|
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
tick becomes due. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
ScheduledJob
|
The scheduled job. |
Source code in src/hassette/scheduler/sync.py
314 315 316 317 318 319 320 321 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 | |
run_minutely(func: JobCallable, minutes: int = 1, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> ScheduledJob
Schedule a job to run every N minutes.
Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
minutes
|
int
|
The minute interval (must be >= 1). |
1
|
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
tick becomes due. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
ScheduledJob
|
The scheduled job. |
Source code in src/hassette/scheduler/sync.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
run_hourly(func: JobCallable, hours: int = 1, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> ScheduledJob
Schedule a job to run every N hours.
Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
hours
|
int
|
The hour interval (must be >= 1). |
1
|
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
tick becomes due. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
ScheduledJob
|
The scheduled job. |
Source code in src/hassette/scheduler/sync.py
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
run_daily(func: JobCallable, at: str = '00:00', *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> ScheduledJob
Schedule a job to run once per day at a fixed wall-clock time.
Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Uses a cron-based trigger internally to ensure DST-correct, wall-clock-aligned scheduling. This avoids the 24-hour drift bug of interval-based daily scheduling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
at
|
str
|
Target wall-clock time in |
'00:00'
|
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
tick becomes due. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
ScheduledJob
|
The scheduled job. |
Source code in src/hassette/scheduler/sync.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
run_cron(func: JobCallable, expression: str, *, name: str, group: str | None = None, jitter: float | None = None, timeout: float | None = None, timeout_disabled: bool = False, mode: ExecutionMode | str | None = None, on_error: SchedulerErrorHandlerType | None = None, if_exists: IfExistsPolicy = 'error', args: tuple[Any, ...] | None = None, kwargs: Mapping[str, Any] | None = None, where: SchedulerPredicate | Sequence[SchedulerPredicate] | None = None) -> ScheduledJob
Schedule a job using a cron expression.
Scheduling completes before the call returns.
job.db_id is a valid integer immediately on return.
Accepts both 5-field (standard Unix cron: minute hour dom month dow)
and 6-field expressions (seconds appended as a 6th field per croniter
convention: minute hour dom month dow second).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
JobCallable
|
The function to run. |
required |
expression
|
str
|
A valid 5- or 6-field cron expression. |
required |
name
|
str
|
Required stable name for the job. |
required |
group
|
str | None
|
Optional group name. |
None
|
jitter
|
float | None
|
Optional seconds of random offset to apply at enqueue time.
See |
None
|
timeout
|
float | None
|
Per-job timeout in seconds. See |
None
|
timeout_disabled
|
bool
|
Disable timeout enforcement. See |
False
|
mode
|
ExecutionMode | str | None
|
Overlap behavior when a prior invocation is still running as the next
tick becomes due. See |
None
|
on_error
|
SchedulerErrorHandlerType | None
|
Optional per-job error handler. See |
None
|
if_exists
|
IfExistsPolicy
|
Behavior when a job with the same name already exists.
See :meth: |
'error'
|
args
|
tuple[Any, ...] | None
|
Positional arguments to pass to the callable when it executes. |
None
|
kwargs
|
Mapping[str, Any] | None
|
Keyword arguments to pass to the callable when it executes. |
None
|
where
|
SchedulerPredicate | Sequence[SchedulerPredicate] | None
|
Optional predicate (or sequence of predicates) gating execution.
See |
None
|
Returns:
| Type | Description |
|---|---|
ScheduledJob
|
The scheduled job. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the cron expression is syntactically invalid. |
Source code in src/hassette/scheduler/sync.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
on_error(handler: SchedulerErrorHandlerType) -> None
Register an app-level error handler for this scheduler.
The handler is called when any job on this scheduler raises an exception
(including TimeoutError) and the job does not have its own
per-registration error handler.
This is an app-level fallback — it is resolved at dispatch time, not at job
registration time. A later call to on_error() replaces any previously
registered handler.
Note: error handlers are spawned as fire-and-forget tasks. Handlers spawned near app shutdown may be cancelled before they complete. Do not rely on error handlers for delivery-critical alerting during system teardown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
SchedulerErrorHandlerType
|
A sync or async callable that accepts a
:class: |
required |
Source code in src/hassette/scheduler/sync.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | |
cancel_job(job: ScheduledJob) -> None
Cancel an individual job and persist the cancellation to the database.
Idempotent: a second cancel on the same job is a silent no-op. Raises
ValueError if the job belongs to a different scheduler instance.
Spawns a durable mark_job_cancelled DB write (when db_id is set),
dequeues the job from the service, and sets job._dequeued = True.
Must NOT call job.cancel() internally — that delegates back here and
would cause infinite recursion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
ScheduledJob
|
The job to cancel. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the job belongs to a different scheduler instance. |
Source code in src/hassette/scheduler/sync.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
cancel_group(group: str) -> None
Cancel all jobs in the given group.
Delegates to cancel_job per-member, which handles the DB write,
dequeue, and _dequeued flag. Dict cleanup (_jobs_by_group and
_jobs_by_name) is handled by the _on_job_removed callback
fired by scheduler_service.dequeue_job. No-op if the group does
not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str
|
The group name to cancel. |
required |
Source code in src/hassette/scheduler/sync.py
685 686 687 688 689 690 691 692 693 694 695 696 697 | |
list_jobs(group: str | None = None) -> list[ScheduledJob]
Return all or group-filtered jobs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str | None
|
If provided, return only jobs in this group.
If |
None
|
Returns:
| Type | Description |
|---|---|
list[ScheduledJob]
|
List of ScheduledJob instances. |
Source code in src/hassette/scheduler/sync.py
699 700 701 702 703 704 705 706 707 708 709 | |
After
One-shot trigger that fires once after a fixed delay.
Accepts seconds, minutes, or a TimeDelta directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float
|
Delay in seconds. |
0
|
minutes
|
float
|
Delay in minutes. |
0
|
timedelta
|
TimeDelta | None
|
Delay as a TimeDelta object. Mutually exclusive with seconds/minutes. |
None
|
Example
After(seconds=30) # fires 30 seconds from now After(minutes=5) # fires 5 minutes from now
Source code in src/hassette/scheduler/triggers.py
32 33 34 35 36 37 38 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 | |
first_run_time(current_time: ZonedDateTime) -> ZonedDateTime
Return current_time plus the delay.
Source code in src/hassette/scheduler/triggers.py
60 61 62 | |
next_run_time(previous_run: ZonedDateTime, current_time: ZonedDateTime) -> None
One-shot trigger; always returns None.
Source code in src/hassette/scheduler/triggers.py
64 65 66 | |
Cron
Trigger based on an arbitrary cron expression.
Accepts both 5-field (standard Unix cron: minute hour dom month dow)
and 6-field expressions (seconds appended as a 6th field per croniter
convention: minute hour dom month dow second).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
A valid 5- or 6-field cron expression. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the expression is syntactically invalid. |
Example
Cron("0 9 * * 1-5") # weekdays at 09:00 Cron("0 9 * * 1-5 0") # weekdays at 09:00:00 (6-field)
Source code in src/hassette/scheduler/triggers.py
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 320 321 322 323 324 325 326 327 | |
first_run_time(current_time: ZonedDateTime) -> ZonedDateTime
Return the first cron-grid-aligned run time at or after current_time.
Source code in src/hassette/scheduler/triggers.py
309 310 311 | |
next_run_time(previous_run: ZonedDateTime, current_time: ZonedDateTime) -> ZonedDateTime
Return the next cron-grid-aligned run time after previous_run that is later than current_time.
Source code in src/hassette/scheduler/triggers.py
313 314 315 | |
Daily
Trigger that fires once per day at a fixed wall-clock time.
Internally delegates to a 5-field cron expression to ensure DST-correct, wall-clock-aligned scheduling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at
|
str
|
Target time in |
required |
Example
Daily(at="07:00") # fires every day at 07:00 wall-clock time
Source code in src/hassette/scheduler/triggers.py
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 | |
first_run_time(current_time: ZonedDateTime) -> ZonedDateTime
Return the next cron-grid-aligned daily run time at or after current_time.
Source code in src/hassette/scheduler/triggers.py
263 264 265 | |
next_run_time(previous_run: ZonedDateTime, current_time: ZonedDateTime) -> ZonedDateTime
Return the next daily run time after previous_run that is later than current_time.
Source code in src/hassette/scheduler/triggers.py
267 268 269 | |
Every
Fixed-interval trigger with drift-resistant scheduling.
Accepts seconds, hours, minutes, or a combination. An optional start
parameter anchors the interval grid; if omitted, the first call to
first_run_time is used as the anchor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float
|
Interval component in seconds. |
0
|
minutes
|
float
|
Interval component in minutes. |
0
|
hours
|
float
|
Interval component in hours. |
0
|
start
|
ZonedDateTime | None
|
Optional |
None
|
Example
Every(hours=1) # every hour, anchored to first run Every(seconds=30, start=my_start_time) # every 30 s, grid anchored to my_start_time
Source code in src/hassette/scheduler/triggers.py
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 227 228 229 230 231 232 233 234 235 236 237 | |
first_run_time(current_time: ZonedDateTime) -> ZonedDateTime
Return the first run time, aligned to the interval grid.
Source code in src/hassette/scheduler/triggers.py
202 203 204 205 206 207 | |
next_run_time(previous_run: ZonedDateTime, current_time: ZonedDateTime) -> ZonedDateTime
Return the next interval tick after previous_run that is later than current_time.
Source code in src/hassette/scheduler/triggers.py
209 210 211 | |
advance_past(anchor: ZonedDateTime, current_time: ZonedDateTime) -> ZonedDateTime
Advance anchor by whole intervals until the result is strictly after current_time.
Source code in src/hassette/scheduler/triggers.py
213 214 215 216 217 218 219 220 221 222 223 224 225 | |
Once
One-shot trigger that fires at a specific wall-clock time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at
|
str | ZonedDateTime
|
Target time. Accepts a |
required |
if_past
|
Literal['tomorrow', 'error']
|
Behavior when the computed fire time is in the past.
- |
'tomorrow'
|
Example
Once(at="07:00") # fires today at 07:00 (or tomorrow if past) Once(at="07:00", if_past="error") # raises if 07:00 has already passed
Source code in src/hassette/scheduler/triggers.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 | |
first_run_time(current_time: ZonedDateTime) -> ZonedDateTime
Return the scheduled fire time.
Source code in src/hassette/scheduler/triggers.py
137 138 139 | |
next_run_time(previous_run: ZonedDateTime, current_time: ZonedDateTime) -> None
One-shot trigger; always returns None.
Source code in src/hassette/scheduler/triggers.py
141 142 143 | |