Package io.meeds.commons.digest.service
Class DigestScheduleStorage
java.lang.Object
io.meeds.commons.digest.service.DigestScheduleStorage
The work list of the digest sender job: who is a candidate, the claim of an
occurrence, the waiting items of a user and their deletion.
-
Constructor Summary
ConstructorsConstructorDescriptionDigestScheduleStorage(DigestUserDAO digestUserDAO, DigestItemDAO digestItemDAO) -
Method Summary
Modifier and TypeMethodDescriptionbooleanclaim(long userId, io.meeds.commons.digest.model.DigestFrequency frequency, Instant expected, Instant now) Claims an occurrence: moves the watermark of the frequency to now, only if it still holds the value the caller read.intSafety cleanup, the first step of every run: the items of users who have no digest enabled any more, and the items older than the retentionintdeleteCoveredItems(String username, Instant coveredUntil) Deletes the items every enabled frequency of the user has coveredfind(long id) findCandidates(io.meeds.commons.digest.model.DigestFrequency frequency, Instant cutoff, long afterId, org.springframework.data.domain.Limit limit) One batch of the candidates of a frequency: the frequency is on and the watermark is older than the cutoff, ids after the last one seen, ascending.The waiting items of a user in a window, most recent firstvoidForgets a user for good: his waiting items and his work list row
-
Constructor Details
-
DigestScheduleStorage
-
-
Method Details
-
findCandidates
public List<DigestUserEntity> findCandidates(io.meeds.commons.digest.model.DigestFrequency frequency, Instant cutoff, long afterId, org.springframework.data.domain.Limit limit) One batch of the candidates of a frequency: the frequency is on and the watermark is older than the cutoff, ids after the last one seen, ascending. The exact "due now in his timezone" check is done in Java by the caller, the query only narrows the set.- Parameters:
frequency- daily or weeklycutoff- the watermark must be before itafterId- only rows with a greater id, 0 for the first batchlimit- how many rows at most- Returns:
- the candidates, by ascending id
-
find
-
claim
@Transactional public boolean claim(long userId, io.meeds.commons.digest.model.DigestFrequency frequency, Instant expected, Instant now) Claims an occurrence: moves the watermark of the frequency to now, only if it still holds the value the caller read. Zero rows means another worker, or another server, took it first. Joins the transaction of the caller when there is one: the claim then commits, or rolls back, with what the caller does with the occurrence.- Parameters:
userId- the work list row idfrequency- daily or weeklyexpected- the watermark the caller readnow- the new watermark- Returns:
- true when this caller got the occurrence
-
findItems
The waiting items of a user in a window, most recent first- Parameters:
username- the recipientafter- excluded lower bound, the previous watermarkuntil- included upper bound, the new watermark- Returns:
- the items
-
deleteCoveredItems
Deletes the items every enabled frequency of the user has covered- Parameters:
username- the recipientcoveredUntil- the oldest watermark of his enabled frequencies- Returns:
- how many items were deleted
-
forget
Forgets a user for good: his waiting items and his work list row- Parameters:
id- the work list row idusername- the user
-
cleanup
Safety cleanup, the first step of every run: the items of users who have no digest enabled any more, and the items older than the retention- Parameters:
retentionLimit- items older than this are deleted whatever happened- Returns:
- how many items were deleted
-