-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #361 remove pgsql quartz vacuum jobs * #361 move cleanup for demo mode and cleanup unreferenced blob to spring scheduled jobs * #361 move special price token generation job in spring managed scheduler, add skip locked in for update clause * #361 move send offline payment reminder to event organizer to spring scheduled jobs * #361 move send email job to spring scheduled jobs * #361 javadoc * #361 move process pending reservations job in spring managed scheduler * #361 remove quartz cron trigger builder helper * #361 move send offline payment reminder job in spring managed scheduler * #361 move send ticket assignment reminder job in spring managed scheduler * #361 move cleanup expired pending reservation job in spring managed scheduler * #361 remove unused query * #361 remove quartz, switch last job * #361 rename job component, email load ids waiting for processing: add a limit of 100 * #361 make some methods publics and transactional, as discovered in the multi threaded test, the transactional annotation are not applied, and thus may cause issues. As an additional measure, the job class has been moved in a separate package * #361 misc cleanup/transactional:readonly=true * #361 add test for cleanupUnreferencedBlobFiles
- Loading branch information
Showing
33 changed files
with
439 additions
and
596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/** | ||
* This file is part of alf.io. | ||
* | ||
* alf.io is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* alf.io is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with alf.io. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package alfio.job; | ||
|
||
import alfio.config.Initializer; | ||
import alfio.manager.*; | ||
import alfio.manager.system.ConfigurationManager; | ||
import alfio.manager.user.UserManager; | ||
import alfio.model.system.Configuration; | ||
import alfio.model.system.ConfigurationKeys; | ||
import alfio.model.user.User; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.apache.commons.lang3.time.DateUtils; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.springframework.context.annotation.DependsOn; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.core.env.Profiles; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
/** | ||
* <p>Scheduled jobs. Important: all the jobs must be able to run on multiple instance at the same time.</p> | ||
* <p>Take great care in placing a select id ... for update skip locked to avoid multiple job execution for the same object</p> | ||
* <p>Note: it's a separate package, as we need to ensure that the called method are public (and possibly @Transactional!)</p> | ||
* | ||
*/ | ||
@Component | ||
@DependsOn("migrator") | ||
@Profile("!" + Initializer.PROFILE_DISABLE_JOBS) | ||
@AllArgsConstructor | ||
@Log4j2 | ||
public class Jobs { | ||
|
||
|
||
private static final int ONE_MINUTE = 1000 * 60; | ||
private static final int THIRTY_SECONDS = 1000 * 30; | ||
private static final int FIVE_SECONDS = 1000 * 5; | ||
private static final int THIRTY_MINUTES = 30 * ONE_MINUTE; | ||
|
||
private final AdminReservationRequestManager adminReservationRequestManager; | ||
private final ConfigurationManager configurationManager; | ||
private final Environment environment; | ||
private final EventManager eventManager; | ||
private final FileUploadManager fileUploadManager; | ||
private final NotificationManager notificationManager; | ||
private final SpecialPriceTokenGenerator specialPriceTokenGenerator; | ||
private final TicketReservationManager ticketReservationManager; | ||
private final UserManager userManager; | ||
private final WaitingQueueSubscriptionProcessor waitingQueueSubscriptionProcessor; | ||
|
||
|
||
//cron each minute: "0 0/1 * * * ?" | ||
|
||
@Scheduled(fixedRate = ONE_MINUTE * 60) | ||
public void cleanupUnreferencedBlobFiles() { | ||
log.trace("running job cleanupUnreferencedBlobFiles"); | ||
fileUploadManager.cleanupUnreferencedBlobFiles(DateUtils.addDays(new Date(), -1)); | ||
} | ||
|
||
|
||
//run each hour | ||
@Scheduled(cron = "0 0 0/1 * * ?") | ||
public void cleanupForDemoMode() { | ||
if (environment.acceptsProfiles(Profiles.of(Initializer.PROFILE_DEMO))) { | ||
log.trace("running job cleanupForDemoMode"); | ||
int expirationDate = configurationManager.getIntConfigValue(Configuration.getSystemConfiguration(ConfigurationKeys.DEMO_MODE_ACCOUNT_EXPIRATION_DAYS), 20); | ||
List<Integer> userIds = userManager.disableAccountsOlderThan(DateUtils.addDays(new Date(), -expirationDate), User.Type.DEMO); | ||
if (!userIds.isEmpty()) { | ||
eventManager.disableEventsFromUsers(userIds); | ||
} | ||
} | ||
} | ||
|
||
@Scheduled(fixedRate = THIRTY_SECONDS) | ||
public void generateSpecialPriceCodes() { | ||
log.trace("running job generateSpecialPriceCodes"); | ||
specialPriceTokenGenerator.generatePendingCodes(); | ||
} | ||
|
||
|
||
//run each hour | ||
@Scheduled(cron = "0 0 0/1 * * ?") | ||
public void sendOfflinePaymentReminderToEventOrganizers() { | ||
log.trace("running job sendOfflinePaymentReminderToEventOrganizers"); | ||
ticketReservationManager.sendReminderForOfflinePaymentsToEventManagers(); | ||
} | ||
|
||
|
||
@Scheduled(fixedRate = FIVE_SECONDS) | ||
public void sendEmails() { | ||
log.trace("running job sendEmails"); | ||
notificationManager.sendWaitingMessages(); | ||
} | ||
|
||
@Scheduled(fixedRate = FIVE_SECONDS) | ||
public void processReservationRequests() { | ||
log.trace("running job processReservationRequests"); | ||
long start = System.currentTimeMillis(); | ||
Pair<Integer, Integer> result = adminReservationRequestManager.processPendingReservations(); | ||
if (result.getLeft() > 0 || result.getRight() > 0) { | ||
log.info("ProcessReservationRequests: got {} success and {} failures. Elapsed {} ms", result.getLeft(), result.getRight(), System.currentTimeMillis() - start); | ||
} | ||
} | ||
|
||
|
||
@Scheduled(fixedRate = THIRTY_MINUTES) | ||
public void sendOfflinePaymentReminder() { | ||
log.trace("running job sendOfflinePaymentReminder"); | ||
ticketReservationManager.sendReminderForOfflinePayments(); | ||
} | ||
|
||
@Scheduled(fixedRate = THIRTY_SECONDS) | ||
public void sendTicketAssignmentReminder() { | ||
log.trace("running job sendTicketAssignmentReminder"); | ||
ticketReservationManager.sendReminderForTicketAssignment(); | ||
ticketReservationManager.sendReminderForOptionalData(); | ||
} | ||
|
||
|
||
@Scheduled(fixedRate = THIRTY_SECONDS) | ||
public void cleanupExpiredPendingReservation() { | ||
log.trace("running job cleanupExpiredPendingReservation"); | ||
//cleanup reservation that have a expiration older than "now minus 10 minutes": this give some additional slack. | ||
final Date expirationDate = DateUtils.addMinutes(new Date(), -10); | ||
ticketReservationManager.cleanupExpiredReservations(expirationDate); | ||
ticketReservationManager.cleanupExpiredOfflineReservations(expirationDate); | ||
ticketReservationManager.markExpiredInPaymentReservationAsStuck(expirationDate); | ||
} | ||
|
||
|
||
@Scheduled(fixedRate = THIRTY_SECONDS) | ||
public void processReleasedTickets() { | ||
log.trace("running job processReleasedTickets"); | ||
waitingQueueSubscriptionProcessor.handleWaitingTickets(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.