-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get running status based on
operation
DB
See also: #7
- Loading branch information
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from operation.models import Operation | ||
|
||
def get_running_status(ch: int) -> tuple[bool, bool]: | ||
"""Gets running status of WLM and the given channel based on operation DB. | ||
Args: | ||
ch: Target channel. | ||
Returns: | ||
Tuple with WLM running status and target channel running status. | ||
""" | ||
latest_operations = ( | ||
Operation.objects.order_by('channel', 'user', '-occured_at').distinct('channel', 'user') | ||
) # latest operations for each channel and user | ||
on_operations = latest_operations.filter(on=True) | ||
is_wlm_running = on_operations.exists() | ||
is_channel_running = on_operations.filter(channel__channel=ch).exists() | ||
return is_wlm_running, is_channel_running |