lablink_allocator_service.scheduler¶
lablink_allocator_service.scheduler
¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
ScheduledDestructionService(schedule_db, db_url, tofu_dir=None)
¶
Initialize the scheduler service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schedule_db
|
ScheduleDatabase
|
ScheduleDatabase instance |
required |
db_url
|
str
|
PostgreSQL connection URL for APScheduler job store |
required |
tofu_dir
|
Optional[str]
|
Path to OpenTofu directory (optional, auto-detected if None) |
None
|
Source code in packages/allocator/src/lablink_allocator_service/scheduler.py
Attributes¶
db_url = db_url
instance-attribute
¶
schedule_db = schedule_db
instance-attribute
¶
scheduler = BackgroundScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults, timezone='UTC')
instance-attribute
¶
tofu_dir = tofu_dir or os.path.join(os.path.dirname(__file__), 'terraform')
instance-attribute
¶
Methods:¶
cancel_scheduled_destruction(schedule_id)
¶
Cancel a scheduled destruction.
Source code in packages/allocator/src/lablink_allocator_service/scheduler.py
schedule_destruction(schedule_name, destruction_time, recurrence_rule=None, created_by=None, notification_enabled=True, notification_hours_before=1)
¶
Schedule a new destruction job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schedule_name
|
str
|
Unique name for the schedule |
required |
destruction_time
|
datetime
|
Initial destruction time (UTC) |
required |
recurrence_rule
|
Optional[str]
|
Optional recurrence rule in RRULE format |
None
|
created_by
|
Optional[str]
|
User who created the schedule |
None
|
notification_enabled
|
bool
|
Whether to enable notifications |
True
|
notification_hours_before
|
int
|
Hours before destruction to notify |
1
|
Returns:
| Type | Description |
|---|---|
int
|
ID of the created schedule in the database |
Source code in packages/allocator/src/lablink_allocator_service/scheduler.py
start()
¶
Start the scheduler and load existing schedules
Source code in packages/allocator/src/lablink_allocator_service/scheduler.py
Functions:¶
execute_scheduled_destruction_job(schedule_id, tofu_dir)
¶
Execute a scheduled destruction job.
This is a standalone function (not a method) to avoid pickling issues with APScheduler's SQLAlchemy job store.
Database credentials and provider configuration are read from the config
system at runtime to avoid storing sensitive data in the APScheduler job
store. Destruction is dispatched through provider.destroy_hosts
(the same path as the /destroy HTTP route) so that all teardown logic
lives in one place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schedule_id
|
int
|
ID of the scheduled destruction |
required |
tofu_dir
|
str
|
Path to OpenTofu directory |
required |
Source code in packages/allocator/src/lablink_allocator_service/scheduler.py
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 | |
run_scheduled_destroy(handles, metrics_db, provider)
¶
Seal session-metrics rows, then tear down the VMs.