feat(프로젝트): 매일 하는 업무 — 날짜 팝업 [매일]·반복 아이콘·시각별 알림

- 마이그레이션 033 tasks.repeat_daily — [매일]이면 마감일·시각 비움, 마감일을 고르면 꺼짐(미적용이면 버튼 숨김·PUT 503)
- 마감 칸(카드·목록·내 업무·세부 업무·업무 창)에 반복 아이콘 + "매일"
- reminders.run_daily_alerts: 영업일, Project 옵션 daily_alert_times 중 지난 가장 늦은 시각마다 담당자(없으면 협업자)에게 type=daily 알림(task_reminders 로 중복 방지, 데몬 1분 주기)
- 큰 알림 팝업·PC 알림 프로그램에서 매일 업무 줄은 노란 배경
- Project 옵션 "알림" 분류: 알림 시각 여러 개 추가·삭제(최대 12)
- 도움말·모듈 CLAUDE.md·DEPLOYMENT(033) 갱신, 테스트 추가

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 14:35:59 +09:00
parent 3045bc6f99
commit 7f94e5efe7
26 changed files with 451 additions and 75 deletions
+70 -12
View File
@@ -15,6 +15,11 @@
"오늘 아직 안 돌았고, 설정 시각이 지났고, 영업일이면" 한 번 돈다. 여러 프로세스가
동시에 돌아도 위 UNIQUE 덕분에 중복 알림이 없다.
매일 하는 업무(033 tasks.repeat_daily, run_daily_alerts) — Project 옵션 daily_alert_times 시각(KST, 영업일)이
지나면 미완료 매일 업무의 담당자(없으면 협업자)에게 수신함 알림(type=daily, 큰 팝업에 따로 색). 데몬은 1분마다 깨어
지난 시각 중 가장 늦은 것 하나만 보낸다(서버가 꺼져 있다 켜져도 몇 번씩 쏟아지지 않게). 중복 방지는 같은
task_reminders(kind='daily@HH:MM', due_date=그날).
환경변수:
PROJECT_REMINDERS false 면 끈다(기본 켜짐)
PROJECT_REMINDER_HOUR 실행 시각(KST 0~23, 기본 9)
@@ -41,6 +46,7 @@ logger = logging.getLogger("project.reminders")
KIND_DUE_SOON = "due_soon"
KIND_DUE_TODAY = "due_today"
KIND_OVERDUE = "overdue"
NTYPE_DAILY = "daily"
OVERDUE_WINDOW_DAYS = 7
@@ -139,6 +145,39 @@ def run_due_reminders(
return counts
def daily_slot(times: list[str], hhmm: str) -> str | None:
"""설정 시각들 중 지금(hhmm)까지 지난 가장 늦은 시각 — 없으면 None."""
passed = [t for t in times if t <= hhmm]
return max(passed) if passed else None
def run_daily_alerts(
st: Any, *, today: date, slot: str, lookup: access.UserLookup | None = None,
) -> int:
"""매일 하는 업무 알림 한 번(그날 slot 시각분). 새로 만든 알림 수. 수신자·권한·중복 규칙은 마감 알림과 같다."""
made = 0
for t in st.list_open_daily_tasks():
assignee = store.norm_str(t.get("assignee_email"), lower=True)
wanted = [assignee] if assignee else store.normalize_emails(t.get("followers") or [])
try:
recipients = access.filter_recipients(st, t, wanted, lookup)
except Exception: # noqa: BLE001 - 권한 확인이 안 되면 이번엔 보내지 않는다
logger.warning("매일 업무 알림 수신자 확인 실패: task=%s", t["id"])
continue
for rcpt in recipients:
try:
created = st.add_reminder_notification(
task_id=t["id"], kind=f"daily@{slot}", due_date=today.isoformat(), recipient_email=rcpt,
project_id=t["project_id"], title=f"매일 업무: {t['title']}",
body=f"{t.get('project_name') or ''} · 매일 {slot}", ntype=NTYPE_DAILY,
)
except Exception: # noqa: BLE001 - 기록도 되돌려졌으니 다음 실행에서 다시 시도
logger.warning("매일 업무 알림 생성 실패(다음 실행에 재시도): task=%s", t["id"])
continue
made += int(bool(created))
return made
def _send_digests(digest: dict[str, list[tuple[str, dict[str, Any]]]], today: date) -> None:
from app.mail import send_email # noqa: WPS433
@@ -176,22 +215,41 @@ def start_reminder_thread(st: Any) -> bool:
def _loop() -> None:
last_run: date | None = None
last_due_try = 0.0
daily_done: tuple[date, str] | None = None # 마지막으로 보낸 (날짜, 시각)
while True:
now = now_kst()
today = now.date()
if time.monotonic() - last_due_try >= 300: # 마감 알림은 예전처럼 5분마다 확인
last_due_try = time.monotonic()
try:
if last_run != today and now.hour >= hour and is_workday(today):
counts = run_due_reminders(st, today=today)
last_run = today
logger.info("마감 알림 실행: %s", counts)
except Exception as exc: # noqa: BLE001
if type(exc).__name__ == "UndefinedTable":
# 008 마이그레이션 미적용 — 오늘은 더 시도하지 않는다(로그 도배 방지)
logger.warning("마감 알림 skip — project_db_008 마이그레이션 필요")
last_run = now_kst().date()
else:
logger.warning("마감 알림 실패(%s) — 5분 뒤 재시도", type(exc).__name__)
try:
now = now_kst()
today = now.date()
if last_run != today and now.hour >= hour and is_workday(today):
counts = run_due_reminders(st, today=today)
last_run = today
logger.info("마감 알림 실행: %s", counts)
if is_workday(today):
times = store.normalize_project_options(st.get_project_options())["daily_alert_times"]
slot = daily_slot(times, now.strftime("%H:%M"))
if slot and daily_done not in ((today, slot), (today, "skip")):
made = run_daily_alerts(st, today=today, slot=slot)
daily_done = (today, slot)
if made:
logger.info("매일 업무 알림 %s: %d건", slot, made)
except Exception as exc: # noqa: BLE001
if type(exc).__name__ == "UndefinedTable":
# 008 마이그레이션 미적용 — 오늘은 더 시도하지 않는다(로그 도배 방지)
logger.warning("마감 알림 skip — project_db_008 마이그레이션 필요")
last_run = now_kst().date()
if type(exc).__name__ in ("UndefinedColumn", "UndefinedTable"):
daily_done = (today, "skip") # 033(또는 008) 미적용 — 오늘은 그만(로그 도배 방지)
logger.warning("매일 업무 알림 skip — project_db_033 마이그레이션 필요")
else:
logger.warning("마감 알림 실패(%s) — 5분 뒤 재시도", type(exc).__name__)
time.sleep(300)
logger.warning("매일 업무 알림 실패(%s) — 1분 뒤 재시도", type(exc).__name__)
time.sleep(60)
threading.Thread(target=_loop, name="project-reminders", daemon=True).start()
return True