Scheduler
Source code in blue/scheduler.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 | |
__init__(task=None, cancel_on_failure=False)
Initializes a new Job instance.
This constructor validates the input types, assigns the scheduling task, and sets up the scheduler and failure policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
(callable, required)
|
The function or callable object that this job will execute when run by the scheduler. Must accept no arguments. |
None
|
cancel_on_failure
|
bool
|
If True, the job will be automatically removed from the scheduler if it raises an unhandled exception during execution. |
False
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
TypeError
|
If |
Source code in blue/scheduler.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
start()
Starts the job by scheduling its execution and beginning the main loop.
This method takes the pre-configured job (self.job) and
then starts a continuous monitoring thread to execute the scheduled tasks.
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in blue/scheduler.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
stop()
Stops the continuous background thread for the scheduler.
This is achieved by calling the set() method on the thread termination
event (self.stop_run_continuously), signaling the scheduler loop to exit
gracefully.
Source code in blue/scheduler.py
53 54 55 56 57 58 59 60 | |
Example - SessionCleanupScheduler
The SessionCleanupScheduler class demonstrates how you can customize the core scheduling logic by extending the existing Scheduler class. For job schedule examples, checkout https://schedule.readthedocs.io/.
Bases: Scheduler
Source code in blue/platform.py
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 | |
__init__(platform, callback)
Initializes a scheduler for session cleanup.
This constructor constructs for scheduler for platform clean up expired session, with an optional callback function. Built on top of scheduler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform
|
str
|
platform name |
required |
callback
|
callable
|
function to execute on schedule |
required |
Source code in blue/platform.py
474 475 476 477 478 479 480 481 482 483 484 485 486 | |
__session_cleanup()
Performs session cleanup.
Based on session_expiration_duration cleans an expired session using last_activity_date of session.
Source code in blue/platform.py
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 | |
set_job()
Sets time to execute scheduler
Source code in blue/platform.py
520 521 522 | |