@@ -123,24 +123,29 @@ private Quarter createQuarter(YearMonth creationDate) {
123123 return generateQuarter (creationDate .atDay (1 ), label );
124124 }
125125
126+ private boolean isFirstMonthOfQuarter (Quarter currentQuarter ) {
127+ YearMonth firstMonth = YearMonth .from (currentQuarter .getStartDate ());
128+ return getCurrentYearMonth ().equals (firstMonth );
129+ }
130+
126131 @ Scheduled (cron = "0 1 0 1 * ?" ) // Runs at 00:01 on the 1st of each month
127132 public void scheduledGenerationQuarters () {
128- logger .warn ("Start scheduling generation quarters" );
133+ logger .warn ("Start scheduled generation of quarters" );
129134 String initialTenant = TenantContext .getCurrentTenant ();
130135
131136 for (String schema : tenantConfigProvider .getAllTenantIds ()) {
132137 logger .warn ("Start generating quarters on first day of month for tenant {}" , schema );
133138 TenantContext .setCurrentTenant (schema );
134139
135140 Quarter currentQuarter = getOrCreateCurrentQuarter ();
136- if (getCurrentYearMonth (). equals ( YearMonth . from ( currentQuarter . getStartDate ()) )) {
141+ if (isFirstMonthOfQuarter ( currentQuarter )) {
137142 YearMonth nextQuarter = YearMonth .from (currentQuarter .getEndDate ()).plusMonths (1 );
138143 createQuarter (nextQuarter );
139144 }
140145 logger .warn ("Successfully generated quarters on first day of month for tenant {}" , schema );
141146 }
142147
143148 TenantContext .setCurrentTenant (initialTenant );
144- logger .warn ("End scheduling generation quarters" );
149+ logger .warn ("End scheduled generation of quarters" );
145150 }
146151}
0 commit comments