SmartJob Executor Service
To get a smartjob.ExecutorService use the function smartjob.get_executor_service.
Then you can use the two methods on smartjob.ExecutorService to execute smartjob.SmartJob jobs (depending on your use-case).
These methods will return a smartjob.ExecutionResult object (when the job is fully executed) or a future on it.
Getting the executor service
smartjob.get_executor_service
Return a singleton instance of ExecutorService (initialized on first call with given arguments).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type |
str
|
The type of executor to use ('cloudrun', 'cloudbatch', 'vertex' or 'docker'). |
'cloudrun'
|
max_workers |
int
|
Maximum number of workers |
DEFAULT_MAX_WORKERS
|
use_cache |
bool
|
if set to True, the same instance will be returned for the same type. |
True
|
Returns:
| Type | Description |
|---|---|
ExecutorService
|
Instance of ExecutorService. |
Source code in smartjob/infra/controllers/lib.py
ExecutorService object
smartjob.ExecutorService
dataclass
Source code in smartjob/app/executor.py
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 | |
run(job, add_envs=None, inputs=None, execution_config=None)
Schedule a job and wait for its completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job |
SmartJob
|
The job to run. |
required |
add_envs |
dict[str, str] | None
|
Environment variables to add for this particular execution. |
None
|
inputs |
list[Input] | None
|
Inputs to add for this particular execution. |
None
|
execution_config |
ExecutionConfig | None
|
Execution configuration. |
None
|
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
The result of the job execution. |
Source code in smartjob/app/executor.py
schedule(job, add_envs=None, inputs=None, execution_config=None, forget=False)
Schedule a job.
This method returns when the job is scheduled (not when it is finished!).
If we can't schedule the job an exception is raised.
If forget=False (default), we return a first object about scheduling details and a second object about the future result of the job execution.
If forget=True, we return only the first object about scheduling details (and None for the second one).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job |
SmartJob
|
The job to run. |
required |
add_envs |
dict[str, str] | None
|
Environment variables to add for this particular execution. |
None
|
inputs |
list[Input] | None
|
Inputs to add for this particular execution. |
None
|
execution_config |
ExecutionConfig | None
|
Execution configuration. |
None
|
forget |
bool
|
if True, don't return a future on ExecutionResult (but None). |
False
|
Returns:
| Type | Description |
|---|---|
tuple[SchedulingDetails, Future[ExecutionResult] | None]
|
The result of the job scheduling and (optionally) a future object about the result of the job execution. |
Source code in smartjob/app/executor.py
ExecutionResult classes
smartjob.SchedulingDetails
dataclass
SchedulingDetails holds some data/details about the scheduling of a job.
Attributes:
| Name | Type | Description |
|---|---|---|
created |
The datetime when the job has started. |
|
execution_id |
str
|
The execution id of the job. |
job_name |
str
|
The name of the job. |
job_namespace |
str
|
The namespace of the job. |
log_url |
str
|
The execution log url. |
Source code in smartjob/app/executor.py
smartjob.ExecutionResult
dataclass
Bases: _ExecutionResult
ExecutionResult is the (final) result of a job execution.
Attributes:
| Name | Type | Description |
|---|---|---|
success |
Whether the job has succeeded or not. |
|
created |
The datetime when the job has started. |
|
stopped |
The datetime when the job has stopped. |
|
execution_id |
The execution id of the job. |
|
job_name |
The name of the job. |
|
job_namespace |
The namespace of the job. |
|
log_url |
The execution log url. |
|
json_output |
dict | list | str | float | int | bool | None
|
if the job has created a json file named smartjob.json in the output directory, it will be stored/decoded here. |