use of com.jeanchampemont.wtfdyum.utils.WTFDYUMException in project WTFDYUM by jchampemont.
the class CronServiceImpl method cron.
@Override
@Scheduled(fixedDelayString = "${wtfdyum.unfollow-check-delay}", initialDelay = 120000L)
public void cron() {
log.debug("Starting cron method...");
final StopWatch watch = new StopWatch();
watch.start();
final Set<Long> members = principalService.getMembers();
for (final Long userId : members) {
try {
final Set<Feature> enabledFeatures = userService.getEnabledFeatures(userId);
final Set<Event> events = new HashSet<>();
for (final Feature enabledFeature : enabledFeatures) {
final Set<Event> es = featureService.cron(userId, enabledFeature);
events.addAll(es);
}
for (final Event e : events) {
userService.addEvent(userId, e);
}
for (final Feature enabledFeature : enabledFeatures) {
featureService.completeCron(userId, enabledFeature);
}
} catch (final WTFDYUMException e) {
if (WTFDYUMExceptionType.GET_FOLLOWERS_RATE_LIMIT_EXCEEDED.equals(e.getType())) {
userService.addEvent(userId, new Event(EventType.RATE_LIMIT_EXCEEDED, null));
log.warn("GET_FOLLOWERS_RATE_LIMIT_EXCEEDED for user id {}", userId);
} else {
userService.addEvent(userId, new Event(EventType.TWITTER_ERROR, null));
log.error("Twitter error for userId " + userId, e.getCause());
}
} catch (final Throwable t) {
userService.addEvent(userId, new Event(EventType.UNKNOWN_ERROR, null));
log.error("Unknown error for user id " + userId, t);
}
}
watch.stop();
log.debug("Finished cron in {} ms", watch.getTotalTimeMillis());
}
use of com.jeanchampemont.wtfdyum.utils.WTFDYUMException in project WTFDYUM by jchampemont.
the class TwitterServiceImpl method getUser.
@Override
public User getUser(final Principal principal, final Long id) throws WTFDYUMException {
User result = null;
try {
final twitter4j.User user = twitter(principal).users().showUser(id);
result = mapper.map(user, User.class);
} catch (final TwitterException e) {
log.debug("Error while getUser", e);
throw new WTFDYUMException(e, WTFDYUMExceptionType.TWITTER_ERROR);
}
return result;
}
Aggregations