Control and supervise
(job)
| 43 | |
| 44 | |
| 45 | def controller(job): |
| 46 | """Control and supervise""" |
| 47 | if not records: |
| 48 | load_records() |
| 49 | |
| 50 | sleep_after = configuration["sleep_after"] |
| 51 | sleepyhead = configuration["sleepyhead"] |
| 52 | notify = configuration["notify"] |
| 53 | peaks = configuration["peaks"] |
| 54 | |
| 55 | if configuration["stochasticity"]["enabled"] is True: |
| 56 | stochasticity(peaks) |
| 57 | |
| 58 | # inspect |
| 59 | supervise, interval, target = inspector(job, peaks) |
| 60 | |
| 61 | if supervise: |
| 62 | if ( |
| 63 | any( |
| 64 | e in [job, job + ("_h" if interval == "hourly" else "_d")] |
| 65 | for e in sleep_after |
| 66 | ) |
| 67 | and target != "lc_extra" |
| 68 | ): |
| 69 | nap = remaining_time(sleepyhead, interval) |
| 70 | send_message(job, "sleep", interval, nap) |
| 71 | |
| 72 | toast_notification(notify, "sleep", job, interval) |
| 73 | sleep_actual(nap) |
| 74 | toast_notification(notify, "wakeup", job, interval) |
| 75 | |
| 76 | else: |
| 77 | if job == "server_calls": |
| 78 | send_message(job, "exit", interval, None) |
| 79 | toast_notification(notify, "exit", job, interval) |
| 80 | |
| 81 | logger.warning( |
| 82 | "You're about to leave the session. " "InstaPy will exit soon!" |
| 83 | ) |
| 84 | exit() |
| 85 | |
| 86 | else: |
| 87 | send_message(job, "jump", interval, None) |
| 88 | return "jump" |
| 89 | |
| 90 | return "available" |
| 91 | |
| 92 | |
| 93 | def inspector(job, peaks): |
no test coverage detected