Worker
CUDOS¤
Inspired by Majordomo Protocol Worker API, ZeroMQ, Python version.
Original MDP/Worker spec
Location: http://rfc.zeromq.org/spec:7.
Author: Min RK benjaminrk@gmail.com
Based on Java example by Arkadiusz Orzechowski
WorkerWatchDog(worker)
¤
Bases: Thread
Class to monitor worker performance
Source code in norfab\core\worker.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
get_ram_usage()
¤
Return RAM usage in Mbyte
Source code in norfab\core\worker.py
83 84 85 |
|
Result(result=None, failed=False, errors=None, task=None, messages=None, juuid=None)
¤
Result of running individual tasks.
Attributes/Arguments:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
changed
|
|
required | |
result
|
Any
|
Result of the task execution, see task's documentation for details |
None
|
failed
|
bool
|
Whether the execution failed or not |
False
|
(logging.LEVEL)
|
severity_level
|
Severity level associated to the result of the execution |
required |
errors
|
Optional[List[str]]
|
exception thrown during the execution of the task (if any) |
None
|
task
|
str
|
Task function name that produced the results |
None
|
messages
|
Optional[List[str]]
|
List of messages produced by the task |
None
|
juuid
|
Optional[str]
|
Job UUID associated with the task |
None
|
Source code in norfab\core\worker.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
dictionary()
¤
Method to serialize result as a dictionary
Source code in norfab\core\worker.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
NFPWorker(broker, service, name, exit_event, log_level='WARNING', log_queue=None, multiplier=6, keepalive=2500)
¤
Parameters:
Name | Type | Description | Default |
---|---|---|---|
broker
|
str
|
str, broker endpoint e.g. tcp://127.0.0.1:5555 |
required |
service
|
str
|
str, service name |
required |
name
|
str
|
str, worker name |
required |
exist_event
|
obj, threading event, if set signal worker to stop |
required | |
multiplier
|
int
|
int, number of keepalives lost before consider other party dead |
6
|
keepalive
|
int
|
int, keepalive interval in milliseconds |
2500
|
Source code in norfab\core\worker.py
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 |
|
reconnect_to_broker()
¤
Connect or reconnect to broker
Source code in norfab\core\worker.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 519 520 521 522 |
|
send_to_broker(command, msg=None)
¤
Send message to broker.
If no msg is provided, creates one internally
Source code in norfab\core\worker.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
|
load_inventory()
¤
Function to load inventory from broker for this worker name.
Source code in norfab\core\worker.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
|
fetch_file(url, raise_on_fail=False, read=True)
¤
Function to download file from broker File Sharing Service
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
file location string in |
required |
raise_on_fail
|
bool
|
raise FIleNotFoundError if download fails |
False
|
read
|
bool
|
if True returns file content, return OS path to saved file otherwise |
True
|
Source code in norfab\core\worker.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
|
fetch_jinja2(url)
¤
Helper function to recursively download Jinja2 template together with other templates referenced using "include" statements
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
|
required |
Source code in norfab\core\worker.py
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 |
|
job_details(uuid, data=True, result=True, events=True)
¤
Method to get job details by UUID for completed jobs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uuid
|
str
|
str, job UUID to return details for |
required |
data
|
bool
|
bool, if True return job data |
True
|
result
|
bool
|
bool, if True return job result |
True
|
events
|
bool
|
bool, if True return job events |
True
|
Returns:
Type | Description |
---|---|
Result
|
Result object with job details |
Source code in norfab\core\worker.py
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 |
|
job_list(pending=True, completed=True, task=None, last=None, client=None, uuid=None)
¤
Method to list worker jobs completed and pending.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pending
|
bool
|
bool, if True or None return pending jobs, if False skip pending jobs |
True
|
completed
|
bool
|
bool, if True or None return completed jobs, if False skip completed jobs |
True
|
task
|
str
|
str, if provided return only jobs with this task name |
None
|
last
|
int
|
int, if provided return only last N completed and last N pending jobs |
None
|
client
|
str
|
str, if provided return only jobs submitted by this client |
None
|
uuid
|
str
|
str, if provided return only job with this UUID |
None
|
Returns:
Type | Description |
---|---|
Result
|
Result object with list of jobs |
Source code in norfab\core\worker.py
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 |
|
request_filename(suuid, base_dir_jobs)
¤
Returns freshly allocated request filename for given UUID str
Source code in norfab\core\worker.py
193 194 195 196 |
|
reply_filename(suuid, base_dir_jobs)
¤
Returns freshly allocated reply filename for given UUID str
Source code in norfab\core\worker.py
199 200 201 202 |
|
event_filename(suuid, base_dir_jobs)
¤
Returns freshly allocated event filename for given UUID str
Source code in norfab\core\worker.py
205 206 207 208 |
|
recv(worker, destroy_event)
¤
Thread to process receive messages from broker.
Source code in norfab\core\worker.py
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 |
|