Kills the session if it is paused for longer than seconds. Parameters ---------- message : str The message to use if the stream is terminated. limit : int The number of seconds the session is allowed to remain paused before it
(self, message, limit, interval)
| 360 | self.tautulli.terminate_session(session_id=self.session_id, message=message) |
| 361 | |
| 362 | def terminate_long_pause(self, message, limit, interval): |
| 363 | """Kills the session if it is paused for longer than <limit> seconds. |
| 364 | |
| 365 | Parameters |
| 366 | ---------- |
| 367 | message : str |
| 368 | The message to use if the stream is terminated. |
| 369 | limit : int |
| 370 | The number of seconds the session is allowed to remain paused before it |
| 371 | is terminated. |
| 372 | interval : int |
| 373 | The amount of time to wait between checks of the session state. |
| 374 | """ |
| 375 | start = datetime.now() |
| 376 | checked_time = 0 |
| 377 | # Continue checking 2 intervals past the allowed limit in order to |
| 378 | # account for system variances. |
| 379 | check_limit = limit + (interval * 2) |
| 380 | |
| 381 | while checked_time < check_limit: |
| 382 | self.get_all_stream_info() |
| 383 | |
| 384 | if self.session_exists is False: |
| 385 | sys.stdout.write( |
| 386 | "Session '{}' from user '{}' is no longer active " |
| 387 | .format(self.session_id, self.username) + |
| 388 | "on the server, stopping monitoring.\n") |
| 389 | return False |
| 390 | |
| 391 | now = datetime.now() |
| 392 | checked_time = (now - start).total_seconds() |
| 393 | |
| 394 | if self.state == 'paused': |
| 395 | if checked_time >= limit: |
| 396 | self.terminate(message) |
| 397 | sys.stdout.write( |
| 398 | "Session '{}' from user '{}' has been killed.\n" |
| 399 | .format(self.session_id, self.username)) |
| 400 | return True |
| 401 | else: |
| 402 | time.sleep(interval) |
| 403 | |
| 404 | elif self.state == 'playing' or self.state == 'buffering': |
| 405 | sys.stdout.write( |
| 406 | "Session '{}' from user '{}' has been resumed, " |
| 407 | .format(self.session_id, self.username) + |
| 408 | "stopping monitoring.\n") |
| 409 | return False |
| 410 | |
| 411 | |
| 412 | class Notification(object): |
no test coverage detected