@@ -35,9 +35,9 @@ import { FindAllRotationDto } from './dto/find-all-rotation.dto';
35
35
36
36
function getRotationCronTime ( ) {
37
37
if ( process . env . NODE_ENV === 'production' ) {
38
- return '59 23 * * 5 ' ;
38
+ return '42 4 27 * * ' ;
39
39
}
40
- return '0 0 * * 5 ' ;
40
+ return '0 0 27 * * ' ;
41
41
}
42
42
43
43
@Injectable ( )
@@ -101,24 +101,53 @@ export class RotationsService {
101
101
}
102
102
103
103
/*
104
- * 매일 0시 0분마다, 현재 날짜가 이번 달 4째주 월요일/금요일인지 확인하여 , 집현전 슬랙 채널에 메세지를 보내는 cron job
104
+ * 매월 23일 , 집현전 슬랙 채널에 메세지를 보내는 cron job
105
105
*/
106
- @Cron ( '0 0 * * *' , {
107
- name : 'sendMessageRotationDeadline ' ,
106
+ @Cron ( '42 15 23 * *' , {
107
+ name : 'sendMessageRotationDeadlineFirst ' ,
108
108
timeZone : 'Asia/Seoul' ,
109
109
} )
110
- async sendMessageRotationDeadline ( ) : Promise < void > {
111
- let message : string ;
112
- const today = new Date ( ) . getDate ( ) ;
113
- if ( today === getFourthMondayOfMonth ( ) ) {
114
- message =
115
- '[알림] 로테이션 신청 기간이 시작되었습니다. 이번 주 금요일까지 신청해주세요!\n[신청하러 가기]: https://together.42jip.net/' ;
116
- } else if ( today === getFourthFridayOfMonth ( ) ) {
117
- message =
118
- '[알림] 로테이션 신청 기간이 내일 마감됩니다. 오늘까지 신청해주세요!\n[신청하러 가기]: https://together.42jip.net/' ;
119
- } else {
120
- return ;
121
- }
110
+ async sendMessageRotationDeadlineFirst ( ) : Promise < void > {
111
+ const message =
112
+ '[알림] 4일 후 로테이션 신청이 마감됩니다.\n[신청하러 가기]: https://together.42jip.net/' ;
113
+
114
+ await this . slackService . postMessage (
115
+ Message ( {
116
+ text : message ,
117
+ channel : this . configService . get ( 'slack.jiphyeonjeonChannel' ) ,
118
+ } ) . buildToObject ( ) ,
119
+ ) ;
120
+ }
121
+
122
+ /*
123
+ * 매월 26일, 집현전 슬랙 채널에 메세지를 보내는 cron job
124
+ */
125
+ @Cron ( '42 15 26 * *' , {
126
+ name : 'sendMessageRotationDeadlineFirst' ,
127
+ timeZone : 'Asia/Seoul' ,
128
+ } )
129
+ async sendMessageRotationDeadlineLast ( ) : Promise < void > {
130
+ const message =
131
+ '[알림] 로테이션 신청 기간이 내일 마감됩니다. 오늘까지 신청해주세요!\n[신청하러 가기]: https://together.42jip.net/' ;
132
+
133
+ await this . slackService . postMessage (
134
+ Message ( {
135
+ text : message ,
136
+ channel : this . configService . get ( 'slack.jiphyeonjeonChannel' ) ,
137
+ } ) . buildToObject ( ) ,
138
+ ) ;
139
+ }
140
+
141
+ /*
142
+ * 매월 27일 사서 로테이션 설정이 완료된 후, 집현전 슬랙 채널에 메세지를 보내는 cron job
143
+ */
144
+ @Cron ( '42 15 27 * *' , {
145
+ name : 'sendMessageRotationDeadlineFirst' ,
146
+ timeZone : 'Asia/Seoul' ,
147
+ } )
148
+ async sendMessageRotationFinished ( ) : Promise < void > {
149
+ const message =
150
+ '[알림] 다음 달 로테이션이 확정되었습니다! 친바 사이트에서 확인해주세요!\n[확인하러 가기]: https://together.42jip.net/' ;
122
151
123
152
await this . slackService . postMessage (
124
153
Message ( {
@@ -159,101 +188,102 @@ export class RotationsService {
159
188
* 매주 금요일을 체크하여, 만약 4주차 금요일인 경우,
160
189
* 23시 59분에 로테이션을 돌린다.
161
190
* 다음 달 로테이션 참석자를 바탕으로 로테이션 결과 반환
191
+ * [update 20240202] - 매월 4주차 금요일이 아닌, 매월 27일 새벽에 로테이션을 돌린다.
162
192
*/
163
193
@Cron ( `${ getRotationCronTime ( ) } ` , {
164
194
name : 'setRotation' ,
165
195
timeZone : 'Asia/Seoul' ,
166
196
} )
167
197
async setRotation ( ) : Promise < void > {
168
- if ( getFourthWeekdaysOfMonth ( ) . indexOf ( getTodayDay ( ) ) > 0 ) {
169
- this . logger . log ( 'Setting rotation...' ) ;
198
+ // if (getFourthWeekdaysOfMonth().indexOf(getTodayDay()) > 0) {
199
+ this . logger . log ( 'Setting rotation...' ) ;
170
200
171
- const { year, month } = getNextYearAndMonth ( ) ;
172
- const attendeeArray : Partial < RotationAttendeeEntity > [ ] = await this . getAllRegistration ( ) ;
173
- const monthArrayInfo : DayObject [ ] [ ] = await this . getInitMonthArray ( year , month ) ;
201
+ const { year, month } = getNextYearAndMonth ( ) ;
202
+ const attendeeArray : Partial < RotationAttendeeEntity > [ ] = await this . getAllRegistration ( ) ;
203
+ const monthArrayInfo : DayObject [ ] [ ] = await this . getInitMonthArray ( year , month ) ;
174
204
175
- if ( ! attendeeArray || attendeeArray . length === 0 ) {
176
- this . logger . warn ( 'No attendees participated in the rotation' ) ;
177
- return ;
178
- }
205
+ if ( ! attendeeArray || attendeeArray . length === 0 ) {
206
+ this . logger . warn ( 'No attendees participated in the rotation' ) ;
207
+ return ;
208
+ }
179
209
180
- const rotationAttendeeInfo : RotationAttendeeInfo [ ] = attendeeArray . map ( ( attendee ) => {
181
- const parsedAttendLimit : number [ ] = Array . isArray ( attendee . attendLimit )
182
- ? JSON . parse ( JSON . stringify ( attendee . attendLimit ) )
183
- : [ ] ;
184
- return {
185
- userId : attendee . userId ,
186
- year : attendee . year ,
187
- month : attendee . month ,
188
- attendLimit : parsedAttendLimit ,
189
- attended : 0 ,
190
- } ;
191
- } ) ;
210
+ const rotationAttendeeInfo : RotationAttendeeInfo [ ] = attendeeArray . map ( ( attendee ) => {
211
+ const parsedAttendLimit : number [ ] = Array . isArray ( attendee . attendLimit )
212
+ ? JSON . parse ( JSON . stringify ( attendee . attendLimit ) )
213
+ : [ ] ;
214
+ return {
215
+ userId : attendee . userId ,
216
+ year : attendee . year ,
217
+ month : attendee . month ,
218
+ attendLimit : parsedAttendLimit ,
219
+ attended : 0 ,
220
+ } ;
221
+ } ) ;
192
222
193
- // 만약 year & month에 해당하는 로테이션 정보가 이미 존재한다면,
194
- // 해당 로테이션 정보를 삭제하고 다시 생성한다.
195
- const hasInfo = await this . rotationRepository . find ( {
223
+ // 만약 year & month에 해당하는 로테이션 정보가 이미 존재한다면,
224
+ // 해당 로테이션 정보를 삭제하고 다시 생성한다.
225
+ const hasInfo = await this . rotationRepository . find ( {
226
+ where : {
227
+ year : year ,
228
+ month : month ,
229
+ } ,
230
+ } ) ;
231
+
232
+ if ( hasInfo . length > 0 ) {
233
+ this . logger . log ( 'Rotation info already exists. Deleting...' ) ;
234
+ await this . rotationRepository . softRemove ( hasInfo ) ;
235
+ }
236
+
237
+ const rotationResultArray : DayObject [ ] = createRotation ( rotationAttendeeInfo , monthArrayInfo ) ;
238
+
239
+ for ( const item of rotationResultArray ) {
240
+ const [ userId1 , userId2 ] = item . arr ;
241
+
242
+ const attendeeOneExist = await this . rotationRepository . findOne ( {
196
243
where : {
244
+ userId : userId1 ,
197
245
year : year ,
198
246
month : month ,
247
+ day : item . day ,
199
248
} ,
200
249
} ) ;
201
250
202
- if ( hasInfo . length > 0 ) {
203
- this . logger . log ( 'Rotation info already exists. Deleting...' ) ;
204
- await this . rotationRepository . softRemove ( hasInfo ) ;
205
- }
206
-
207
- const rotationResultArray : DayObject [ ] = createRotation ( rotationAttendeeInfo , monthArrayInfo ) ;
251
+ if ( ! attendeeOneExist ) {
252
+ const rotation1 = new RotationEntity ( ) ;
253
+ rotation1 . userId = userId1 ;
254
+ rotation1 . updateUserId = userId1 ;
255
+ rotation1 . year = year ;
256
+ rotation1 . month = month ;
257
+ rotation1 . day = item . day ;
208
258
209
- for ( const item of rotationResultArray ) {
210
- const [ userId1 , userId2 ] = item . arr ;
211
-
212
- const attendeeOneExist = await this . rotationRepository . findOne ( {
213
- where : {
214
- userId : userId1 ,
215
- year : year ,
216
- month : month ,
217
- day : item . day ,
218
- } ,
219
- } ) ;
220
-
221
- if ( ! attendeeOneExist ) {
222
- const rotation1 = new RotationEntity ( ) ;
223
- rotation1 . userId = userId1 ;
224
- rotation1 . updateUserId = userId1 ;
225
- rotation1 . year = year ;
226
- rotation1 . month = month ;
227
- rotation1 . day = item . day ;
228
-
229
- await this . rotationRepository . save ( rotation1 ) ;
230
- }
259
+ await this . rotationRepository . save ( rotation1 ) ;
260
+ }
231
261
232
- const attendeeTwoExist = await this . rotationRepository . findOne ( {
233
- where : {
234
- userId : userId2 ,
235
- year : year ,
236
- month : month ,
237
- day : item . day ,
238
- } ,
239
- } ) ;
262
+ const attendeeTwoExist = await this . rotationRepository . findOne ( {
263
+ where : {
264
+ userId : userId2 ,
265
+ year : year ,
266
+ month : month ,
267
+ day : item . day ,
268
+ } ,
269
+ } ) ;
240
270
241
- if ( ! attendeeTwoExist ) {
242
- const rotation2 = new RotationEntity ( ) ;
243
- rotation2 . userId = userId2 ;
244
- rotation2 . updateUserId = userId2 ;
245
- rotation2 . year = year ;
246
- rotation2 . month = month ;
247
- rotation2 . day = item . day ;
271
+ if ( ! attendeeTwoExist ) {
272
+ const rotation2 = new RotationEntity ( ) ;
273
+ rotation2 . userId = userId2 ;
274
+ rotation2 . updateUserId = userId2 ;
275
+ rotation2 . year = year ;
276
+ rotation2 . month = month ;
277
+ rotation2 . day = item . day ;
248
278
249
- await this . rotationRepository . save ( rotation2 ) ;
250
- }
279
+ await this . rotationRepository . save ( rotation2 ) ;
251
280
}
252
-
253
- this . logger . log ( 'Successfully set rotation!' ) ;
254
- } else {
255
- // skipped...
256
281
}
282
+
283
+ this . logger . log ( 'Successfully set rotation!' ) ;
284
+ // } else {
285
+ // // skipped...
286
+ // }
257
287
}
258
288
259
289
/*
0 commit comments