Skip to content

Commit 92f8efb

Browse files
authored
Merge pull request #160 from sjefferson99/159-card-scheduler-considers-the-whole-board-for-duplication
159 card scheduler considers the whole board for duplication
2 parents 8028ce4 + 82c7c4c commit 92f8efb

File tree

3 files changed

+352
-5
lines changed

3 files changed

+352
-5
lines changed

server/app.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
logger = logging.getLogger(__name__)
2222

2323
# Application version
24-
APP_VERSION = "1.2.0"
24+
APP_VERSION = "1.2.1"
2525

2626
# Settings schema - defines allowed settings and their validation rules
2727
SETTINGS_SCHEMA = {
@@ -3312,13 +3312,20 @@ def create_card(column_id):
33123312
if scheduled is not None and not isinstance(scheduled, bool):
33133313
return create_error_response("Scheduled must be a boolean", 400)
33143314

3315+
# Validate schedule parameter if provided
3316+
schedule = data.get("schedule")
3317+
if schedule is not None:
3318+
if not isinstance(schedule, int):
3319+
return create_error_response("Schedule must be an integer", 400)
3320+
33153321
# Create card
33163322
card = Card(
33173323
column_id=column_id,
33183324
title=title,
33193325
description=description,
33203326
order=order,
3321-
scheduled=scheduled
3327+
scheduled=scheduled,
3328+
schedule=schedule
33223329
)
33233330
db.add(card)
33243331
db.commit()
@@ -3330,6 +3337,9 @@ def create_card(column_id):
33303337
"title": card.title,
33313338
"description": card.description,
33323339
"order": card.order,
3340+
"scheduled": card.scheduled,
3341+
"schedule": card.schedule,
3342+
"archived": card.archived
33333343
}
33343344

33353345
return create_success_response({"card": result}, status_code=201)
@@ -3814,6 +3824,13 @@ def update_card(card_id):
38143824

38153825
card.description = description
38163826

3827+
# Update archived status if provided
3828+
if "archived" in data:
3829+
archived = data["archived"]
3830+
if not isinstance(archived, bool):
3831+
return create_error_response("Archived must be a boolean", 400)
3832+
card.archived = archived
3833+
38173834
# Handle column and order changes
38183835
if "column_id" in data or "order" in data:
38193836
new_column_id = data.get("column_id", card.column_id)

server/card_scheduler.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,26 @@ def _process_schedule(self, db, schedule: ScheduledCard, now: datetime):
199199
# This prevents creating duplicate cards if the scheduler runs multiple times
200200
# within the lookback window (e.g., after a restart)
201201
if not schedule.allow_duplicates: # type: ignore
202-
# For non-duplicate schedules, check if any active cards exist from this schedule
202+
# Get the template card to check its column
203+
template = db.query(Card).filter(Card.id == schedule.card_id).first()
204+
if not template:
205+
logger.error(f"Template card {schedule.card_id} not found for schedule {schedule.id}")
206+
return
207+
208+
# For non-duplicate schedules, check if any active cards exist from this schedule IN THE SAME COLUMN
203209
# This is a simple but effective way to prevent duplicates without needing timestamps
204210
existing_card = (
205211
db.query(Card)
212+
.filter(Card.column_id == template.column_id) # Check same column only
206213
.filter(Card.schedule == schedule.id)
207214
.filter(Card.scheduled.is_(False)) # Don't count template cards
208215
.filter(Card.archived.is_(False)) # Only check active cards
209216
.first()
210217
)
211218

212219
if existing_card:
213-
# Already have an active card for this schedule, skip
214-
logger.debug(f"Skipping schedule {schedule.id} - active card already exists")
220+
# Already have an active card for this schedule in this column, skip
221+
logger.debug(f"Skipping schedule {schedule.id} - active card already exists in column {template.column_id}")
215222
return
216223

217224
logger.info(f"Creating card for schedule {schedule.id} (missed by {time_since_run:.0f} seconds)")

0 commit comments

Comments
 (0)