Skip to content

Commit

Permalink
Merge pull request #133 from bjester/release-v0.6.x
Browse files Browse the repository at this point in the history
Add new ids argument to cleanupsyncs command
  • Loading branch information
bjester authored Sep 9, 2021
2 parents 5a0c3ac + 73299db commit 0541457
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .buildkite/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -euo pipefail

mkdir -p dist
make dist
buildkite-agent artifact upload 'dist/*.whl'
buildkite-agent artifact upload 'dist/*.tar.gz'
10 changes: 10 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
steps:
- label: Install build packages
command:
- pip install setuptools wheel

- wait

- label: Build python package
command:
- .buildkite/build.sh
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ List of the most important changes for each release.
## 0.6.5
- Sets queuing limit of 100k combined FSICs between client and server
- Fixes SQL expression tree error when there are many FSICs, up to 100k limit
- Adds additional `ids` argument to `cleanupsyncs` management command

## 0.6.4
- Fixes issue with `assert` statement removal during python optimization
Expand Down
11 changes: 11 additions & 0 deletions morango/management/commands/cleanupsyncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class Command(BaseCommand):
help = "Closes and cleans up the data for any incomplete sync sessions older than a certain number of hours."

def add_arguments(self, parser):
parser.add_argument(
"--ids",
type=lambda ids: ids.split(","),
default=None,
help="Comma separated list of SyncSession IDs to filter against"
)
parser.add_argument(
"--expiration",
action="store",
Expand All @@ -28,6 +34,11 @@ def handle(self, *args, **options):
oldsessions = TransferSession.objects.filter(
last_activity_timestamp__lt=cutoff, active=True
)

# if ids arg was passed, filter down sessions to only those IDs if included by expiration filter
if options["ids"]:
oldsessions = oldsessions.filter(sync_session_id__in=options["ids"])

sesscount = oldsessions.count()

# loop over the stale sessions one by one to close them out
Expand Down
13 changes: 11 additions & 2 deletions tests/testapp/tests/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from django.utils import timezone

from .helpers import create_buffer_and_store_dummy_data
from morango.models.core import Buffer
from morango.models.core import RecordMaxCounterBuffer
from morango.models.core import SyncSession
from morango.models.core import TransferSession

Expand Down Expand Up @@ -72,3 +70,14 @@ def test_all_sessions_cleared(self):
call_command("cleanupsyncs", expiration=1)
assert_session_is_cleared(self.transfersession_old)
assert_session_is_cleared(self.transfersession_new)

def test_filtering_sessions_cleared(self):
call_command("cleanupsyncs", ids=[self.syncsession_old.id], expiration=0)
assert_session_is_cleared(self.transfersession_old)
assert_session_is_not_cleared(self.transfersession_new)

def test_multiple_ids_as_list(self):
ids = [self.syncsession_old.id, self.syncsession_new.id]
call_command("cleanupsyncs", ids=ids, expiration=0)
assert_session_is_cleared(self.transfersession_old)
assert_session_is_cleared(self.transfersession_new)

0 comments on commit 0541457

Please sign in to comment.