()
| 732 | |
| 733 | @staticmethod |
| 734 | def list(): |
| 735 | processes = Process.for_user() |
| 736 | changed = False |
| 737 | |
| 738 | browser_preference = Preferences.module('browser') |
| 739 | expiry_add = timedelta( |
| 740 | browser_preference.preference('process_retain_days').get() or 1 |
| 741 | ) |
| 742 | |
| 743 | res = [] |
| 744 | for p in [*processes]: |
| 745 | if p.start_time is not None: |
| 746 | # remove expired jobs |
| 747 | process_expiration_time = \ |
| 748 | parser.parse(p.start_time) + expiry_add |
| 749 | if datetime.now(process_expiration_time.tzinfo) >= \ |
| 750 | process_expiration_time: |
| 751 | shutil.rmtree(p.logdir, True) |
| 752 | db.session.delete(p) |
| 753 | changed = True |
| 754 | |
| 755 | status, updated = BatchProcess.update_process_info(p) |
| 756 | if not status: |
| 757 | continue |
| 758 | elif not changed: |
| 759 | changed = updated |
| 760 | |
| 761 | if p.start_time is None or ( |
| 762 | p.acknowledge is not None and p.end_time is None |
| 763 | ): |
| 764 | continue |
| 765 | |
| 766 | stime = parser.parse(p.start_time) |
| 767 | etime = parser.parse(p.end_time or get_current_time()) |
| 768 | |
| 769 | execution_time = BatchProcess.total_seconds(etime - stime) |
| 770 | |
| 771 | desc, details, type_desc, current_storage_dir = BatchProcess.\ |
| 772 | _check_process_desc(p) |
| 773 | |
| 774 | res.append({ |
| 775 | 'id': p.pid, |
| 776 | 'desc': desc, |
| 777 | 'type_desc': type_desc, |
| 778 | 'details': details, |
| 779 | 'stime': stime, |
| 780 | 'etime': p.end_time, |
| 781 | 'exit_code': p.exit_code, |
| 782 | 'acknowledge': p.acknowledge, |
| 783 | 'execution_time': execution_time, |
| 784 | 'process_state': p.process_state, |
| 785 | 'utility_pid': p.utility_pid, |
| 786 | 'server_id': p.server_id, |
| 787 | 'current_storage_dir': current_storage_dir, |
| 788 | }) |
| 789 | |
| 790 | if changed: |
| 791 | db.session.commit() |
no test coverage detected