Skip to content

Commit 96aa3d1

Browse files
authored
빈자리알림 검색 페이지 요청 시 학기 명시 (#510)
1 parent b8fd12b commit 96aa3d1

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

batch/src/main/kotlin/sugangsnu/common/SugangSnuRepository.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,19 @@ class SugangSnuRepository(
5151
""".trimIndent().replace("\n", "")
5252
}
5353

54-
suspend fun getSearchPageHtml(pageNo: Int = 1): PooledDataBuffer =
54+
suspend fun getSearchPageHtml(
55+
year: Int,
56+
semester: Semester,
57+
pageNo: Int = 1,
58+
): PooledDataBuffer =
5559
sugangSnuApi
5660
.get()
5761
.uri { builder ->
5862
builder
5963
.path(SUGANG_SNU_SEARCH_PATH)
6064
.query(DEFAULT_SEARCH_PAGE_PARAMS)
65+
.queryParam("srchOpenSchyy", year)
66+
.queryParam("srchOpenShtm", convertSemesterToSugangSnuSearchString(semester))
6167
.queryParam("pageNo", pageNo)
6268
.build()
6369
}.accept(MediaType.TEXT_HTML)

batch/src/main/kotlin/sugangsnu/job/vacancynotification/service/VacancyNotifierService.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class VacancyNotifierServiceImpl(
6565
log.info("시작: ${registrationPhase.name}")
6666
val pageCount =
6767
runCatching {
68-
getPageCount()
68+
getPageCount(coursebook)
6969
}.getOrElse {
7070
log.error("에러가 발생했거나 부하 기간입니다. {}", it.message, it)
7171
delay(30L.seconds)
@@ -77,7 +77,7 @@ class VacancyNotifierServiceImpl(
7777

7878
// 수강 사이트 부하를 분산하기 위해 강의 전체를 20등분해서 각각 요청
7979
(1..pageCount).chunked(pageCount / 20).forEach { chunkedPages ->
80-
val registrationStatus = getRegistrationStatus(chunkedPages)
80+
val registrationStatus = getRegistrationStatus(chunkedPages, coursebook)
8181
if (registrationStatus.all { it.registrationCount == 0 }) return VacancyNotificationJobResult.REGISTRATION_IS_NOT_STARTED
8282

8383
val registrationStatusMap =
@@ -157,19 +157,22 @@ class VacancyNotifierServiceImpl(
157157
this.quota == this.registrationCount
158158
}
159159

160-
private suspend fun getPageCount(): Int {
161-
val firstPageContent = getSugangSnuSearchContent(1)
160+
private suspend fun getPageCount(coursebook: Coursebook): Int {
161+
val firstPageContent = getSugangSnuSearchContent(1, coursebook)
162162
val totalCount =
163163
firstPageContent.select("div.content > div.search-result-con > small > em").text().toInt()
164164
return (totalCount + 9) / COUNT_PER_PAGE
165165
}
166166

167-
private suspend fun getRegistrationStatus(pages: List<Int>): List<RegistrationStatus> =
167+
private suspend fun getRegistrationStatus(
168+
pages: List<Int>,
169+
coursebook: Coursebook,
170+
): List<RegistrationStatus> =
168171
supervisorScope {
169172
pages
170173
.map { page ->
171174
async {
172-
getSugangSnuSearchContent(page).extractRegistrationStatus()
175+
getSugangSnuSearchContent(page, coursebook).extractRegistrationStatus()
173176
}
174177
}.awaitAll()
175178
.flatten()
@@ -211,8 +214,16 @@ class VacancyNotifierServiceImpl(
211214
}
212215
}
213216

214-
private suspend fun getSugangSnuSearchContent(pageNo: Int): Element {
215-
val webPageDataBuffer = sugangSnuRepository.getSearchPageHtml(pageNo)
217+
private suspend fun getSugangSnuSearchContent(
218+
pageNo: Int,
219+
coursebook: Coursebook,
220+
): Element {
221+
val webPageDataBuffer =
222+
sugangSnuRepository.getSearchPageHtml(
223+
year = coursebook.year,
224+
semester = coursebook.semester,
225+
pageNo = pageNo,
226+
)
216227
return try {
217228
Jsoup
218229
.parse(webPageDataBuffer.asInputStream(), Charsets.UTF_8.name(), "")

0 commit comments

Comments
 (0)