Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 40 additions & 206 deletions src/main/java/org/woehlke/twitterwall/ScheduledTasks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.woehlke.twitterwall.conf.TwitterwallSchedulerProperties;
import org.woehlke.twitterwall.scheduled.service.facade.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.woehlke.twitterwall.scheduled.mq.endoint.StartTask;

/**
* Created by tw on 10.06.17.
Expand All @@ -20,45 +17,50 @@
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
public class ScheduledTasks {

private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);

private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

private final TwitterwallSchedulerProperties twitterwallSchedulerProperties;

private void logEnv(String msg){
log.info("====================================================================");
log.info(msg);
log.info("====================================================================");
log.info("twitterwall.scheduler.allowUpdateTweets = "+ twitterwallSchedulerProperties.getAllowUpdateTweets());
log.info("twitterwall.scheduler.allowUpdateUserProfiles = "+ twitterwallSchedulerProperties.getAllowUpdateUserProfiles());
log.info("twitterwall.scheduler.allowUpdateUserProfilesFromMention = "+ twitterwallSchedulerProperties.getAllowUpdateUserProfilesFromMention());
log.info("twitterwall.scheduler.allowFetchTweetsFromTwitterSearch = "+ twitterwallSchedulerProperties.getAllowFetchTweetsFromTwitterSearch());
log.info("twitterwall.scheduler.skipFortesting = "+ twitterwallSchedulerProperties.getSkipFortesting());
log.info("twitterwall.scheduler.herokuDbRowsLimit = "+ twitterwallSchedulerProperties.getHerokuDbRowsLimit());
log.info("twitterwall.scheduler.fetchUserList.name = "+ twitterwallSchedulerProperties.getFetchUserList().getName());
log.info("twitterwall.scheduler.fetchUserList.allow = "+ twitterwallSchedulerProperties.getFetchUserList().getAllow());
log.info("====================================================================");
@Scheduled(fixedRate = FIXED_RATE_FOR_SCHEDULAR_FETCH_TWEETS)
public void fetchTweetsFromTwitterSearch() {
String msg = "fetch Tweets From TwitterSearch ";
if(twitterwallSchedulerProperties.getAllowUpdateTweets() && !twitterwallSchedulerProperties.getSkipFortesting()) {
startTask.fetchTweetsFromTwitterSearch();
}
}

private final FetchTweetsFromTwitterSearch fetchTweetsFromTwitterSearch;

private final FetchUsersFromDefinedUserList fetchUsersFromDefinedUserList;
@Scheduled(fixedRate = FIXED_RATE_FOR_SCHEDULAR_UPDATE_TWEETS)
public void updateTweets() {
String msg = "update Tweets ";
if(twitterwallSchedulerProperties.getAllowUpdateTweets() && !twitterwallSchedulerProperties.getSkipFortesting()){
startTask.updateTweets();
}
}

private final UpdateTweets updateTweets;
@Scheduled(fixedRate = FIXED_RATE_FOR_SCHEDULAR_UPDATE_USER)
public void updateUserProfiles() {
String msg = "update User Profiles ";
if(twitterwallSchedulerProperties.getAllowUpdateUserProfiles() && !twitterwallSchedulerProperties.getSkipFortesting()) {
startTask.updateUserProfiles();
}
}

private final UpdateUserProfiles updateUserProfiles;
@Scheduled(fixedRate = FIXED_RATE_FOR_SCHEDULAR_UPDATE_USER_BY_MENTION)
public void updateUserProfilesFromMentions(){
String msg = "update User Profiles From Mentions";
if(twitterwallSchedulerProperties.getAllowUpdateUserProfilesFromMention() && !twitterwallSchedulerProperties.getSkipFortesting()) {
startTask.updateUserProfilesFromMentions();
}
}

private final UpdateUserProfilesFromMentions updateUserProfilesFromMentions;
@Scheduled(fixedRate = FIXED_RATE_FOR_SCHEDULAR_FETCH_USER_LIST)
public void fetchUsersFromDefinedUserList(){
String msg = "fetch Users from Defined User List ";
if(twitterwallSchedulerProperties.getFetchUserList().getAllow() && !twitterwallSchedulerProperties.getSkipFortesting()) {
startTask.fetchUsersFromDefinedUserList();
}
}

@Autowired
public ScheduledTasks(TwitterwallSchedulerProperties twitterwallSchedulerProperties, FetchTweetsFromTwitterSearch fetchTweetsFromTwitterSearch, FetchUsersFromDefinedUserList fetchUsersFromDefinedUserList, UpdateTweets updateTweets, UpdateUserProfiles updateUserProfiles, UpdateUserProfilesFromMentions updateUserProfilesFromMentions) {
public ScheduledTasks(TwitterwallSchedulerProperties twitterwallSchedulerProperties, StartTask startTask) {
this.twitterwallSchedulerProperties = twitterwallSchedulerProperties;
this.fetchTweetsFromTwitterSearch = fetchTweetsFromTwitterSearch;
this.fetchUsersFromDefinedUserList = fetchUsersFromDefinedUserList;
this.updateTweets = updateTweets;
this.updateUserProfiles = updateUserProfiles;
this.updateUserProfilesFromMentions = updateUserProfilesFromMentions;
this.startTask = startTask;
}

private final static long EINE_MINUTE = 60 * 1000;
Expand All @@ -79,177 +81,9 @@ public ScheduledTasks(TwitterwallSchedulerProperties twitterwallSchedulerPropert

private final static long FIXED_RATE_FOR_SCHEDULAR_FETCH_USER_LIST = ZWOELF_STUNDEN;

//@Scheduled(fixedRate = FIXED_RATE_FOR_SCHEDULAR_FETCH_TWEETS)
public void fetchTweetsFromTwitterSearch() {
String msg = "fetch Tweets From TwitterSearch ";
logEnv(msg);
if(twitterwallSchedulerProperties.getAllowUpdateTweets() && !twitterwallSchedulerProperties.getSkipFortesting()){
log.info("START "+msg+": The time is now {}", dateFormat.format(new Date()));
try {
this.fetchTweetsFromTwitterSearch.fetchTweetsFromTwitterSearch();
log.info("DONE "+msg+" (OK)"+": The time is now {}", dateFormat.format(new Date()));
} catch (RuntimeException e) {
msg += " (RuntimeException) ";
String eMesg = e.getMessage();
e.printStackTrace();
Throwable t = e.getCause();
while(t != null){
log.warn(msg + t.getMessage());
t = t.getCause();
}
log.error(msg +" : " + eMesg);
log.error("NOT DONE "+msg+" (NOK)");;
} catch (Exception e) {
msg += " (Exception) ";
String eMesg = e.getMessage();
e.printStackTrace();
Throwable t = e.getCause();
while(t != null){
log.warn(msg + t.getMessage());
t = t.getCause();
}
log.error(msg +" : " + eMesg);
log.error("NOT DONE "+msg+" (NOK)");;
}
}
logEnv(msg);
}

//@Scheduled(fixedRate = FIXED_RATE_FOR_SCHEDULAR_UPDATE_TWEETS)
public void updateTweets() {
String msg = "update Tweets ";
logEnv(msg);
if(twitterwallSchedulerProperties.getAllowUpdateTweets() && !twitterwallSchedulerProperties.getSkipFortesting()){
log.info("START "+msg + ": The time is now {}", dateFormat.format(new Date()));
try {
this.updateTweets.updateTweets();
log.info("DONE "+msg+" (OK)"+": The time is now {}", dateFormat.format(new Date()));
} catch (RuntimeException e) {
msg += " (RuntimeException) ";
String eMsg = e.getMessage();
log.warn(msg + e.getMessage());
Throwable t = e.getCause();
e.printStackTrace();
while(t != null){
log.warn(msg + t.getMessage());
t = t.getCause();
}
log.warn(msg + eMsg);
log.warn("NOT DONE "+msg+" (NOK) {}", dateFormat.format(new Date()));;
} catch (Exception e) {
msg += " (Exception) ";
String eMsg = e.getMessage();
Throwable t = e.getCause();
while(t != null){
log.warn(msg + t.getMessage());
t = t.getCause();
}
log.warn(msg + eMsg);
log.warn("NOT DONE "+msg+" (NOK) {}", dateFormat.format(new Date()));
}
}
logEnv(msg);
}

//@Scheduled(fixedRate = FIXED_RATE_FOR_SCHEDULAR_UPDATE_USER)
public void updateUserProfiles() {
String msg = "update User Profiles ";
logEnv(msg);
if(twitterwallSchedulerProperties.getAllowUpdateUserProfiles() && !twitterwallSchedulerProperties.getSkipFortesting()) {
log.info("START " + msg + ": The time is now {}", dateFormat.format(new Date()));
try {
//this.updateUserProfiles.updateUserProfiles();
log.info("DONE " + msg + " (OK)" + ": The time is now {}", dateFormat.format(new Date()));
} catch (RuntimeException e) {
msg += " (RuntimeException) ";
String eMsg = e.getMessage();
Throwable t = e.getCause();
while(t != null){
log.warn(msg + t.getMessage());
t = t.getCause();
}
log.warn(msg + eMsg);
log.warn(msg + " NOT DONE " + msg + " (NOK) {}", dateFormat.format(new Date()));
} catch (Exception e) {
msg += " (Exception) ";
String eMsg = e.getMessage();
Throwable t = e.getCause();
while(t != null){
log.warn(msg + t.getMessage());
t = t.getCause();
}
log.warn(msg + eMsg);
log.error(msg + " NOT DONE " + msg + " (NOK) {}", dateFormat.format(new Date()));
}
}
logEnv(msg);
}
private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);

//@Scheduled(fixedRate = FIXED_RATE_FOR_SCHEDULAR_UPDATE_USER_BY_MENTION)
public void updateUserProfilesFromMentions(){
String msg = "update User Profiles From Mentions";
logEnv(msg);
if(twitterwallSchedulerProperties.getAllowUpdateUserProfilesFromMention() && !twitterwallSchedulerProperties.getSkipFortesting()) {
log.info("START " + msg + ": The time is now {}", dateFormat.format(new Date()));
try {
//this.updateUserProfilesFromMentions.updateUserProfilesFromMentions();
log.info("DONE " + msg + " (OK)" + ": The time is now {}", dateFormat.format(new Date()));
} catch (RuntimeException e) {
msg += " (RuntimeException) ";
String eMsg = e.getMessage();
Throwable t = e.getCause();
while(t != null){
log.warn(msg + t.getMessage());
t = t.getCause();
}
log.warn(msg + eMsg);
log.warn(msg + " NOT DONE " + msg + " (NOK) {}", dateFormat.format(new Date()));
} catch (Exception e) {
msg += " (Exception) ";
String eMsg = e.getMessage();
Throwable t = e.getCause();
while(t != null){
log.warn(msg + t.getMessage());
t = t.getCause();
}
log.warn(msg + eMsg);
log.error(msg + " NOT DONE " + msg + " (NOK) {}", dateFormat.format(new Date()));
}
}
logEnv(msg);
}
private final TwitterwallSchedulerProperties twitterwallSchedulerProperties;

//@Scheduled(fixedRate = FIXED_RATE_FOR_SCHEDULAR_FETCH_USER_LIST)
public void fetchUsersFromDefinedUserList(){
String msg = "fetch Users from Defined User List ";
logEnv(msg);
if(twitterwallSchedulerProperties.getFetchUserList().getAllow() && !twitterwallSchedulerProperties.getSkipFortesting()) {
log.info("START " + msg + ": The time is now {}", dateFormat.format(new Date()));
try {
this.fetchUsersFromDefinedUserList.fetchUsersFromDefinedUserList();
log.info("DONE " + msg + " (OK)" + ": The time is now {}", dateFormat.format(new Date()));
} catch (RuntimeException e) {
msg += " (RuntimeException) ";
String eMsg = e.getMessage();
Throwable t = e.getCause();
while(t != null){
log.warn(msg + t.getMessage());
t = t.getCause();
}
log.warn(msg + eMsg);
log.warn(msg + " NOT DONE " + msg + " (NOK) {}", dateFormat.format(new Date()));
} catch (Exception e) {
msg += " (Exception) ";
String eMsg = e.getMessage();
Throwable t = e.getCause();
while(t != null){
log.warn(msg + t.getMessage());
t = t.getCause();
}
log.error(msg + eMsg);
log.error(msg + " NOT DONE " + msg + " (NOK) {}", dateFormat.format(new Date()));
}
}
logEnv(msg);
}
private final StartTask startTask;
}
11 changes: 11 additions & 0 deletions src/main/java/org/woehlke/twitterwall/conf/TwitterProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class TwitterProperties {
@NotNull
private Integer pageSize;

@NotNull
private Integer millisToWaitBetweenTwoApiCalls;

@NotNull
private String searchQuery;

Expand Down Expand Up @@ -77,4 +80,12 @@ public String getSearchQuery() {
public void setSearchQuery(String searchQuery) {
this.searchQuery = searchQuery;
}

public Integer getMillisToWaitBetweenTwoApiCalls() {
return millisToWaitBetweenTwoApiCalls;
}

public void setMillisToWaitBetweenTwoApiCalls(Integer millisToWaitBetweenTwoApiCalls) {
this.millisToWaitBetweenTwoApiCalls = millisToWaitBetweenTwoApiCalls;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class ApplicationController {
@RequestMapping(path="/domain/count")
public String domainCount(Model model) {
String msg = "/application/domain/count: ";
controllerHelper.logEnv();
String title = "Counted Entities";
String subtitle = twitterProperties.getSearchQuery();
String symbol = Symbols.DATABASE.toString();
Expand All @@ -33,27 +32,22 @@ public String domainCount(Model model) {
@RequestMapping(path="/management")
public String dmanagementPage(Model model) {
String msg = "/application/domain/count: ";
controllerHelper.logEnv();
String title = "Application Management";
String subtitle = twitterProperties.getSearchQuery();
String symbol = Symbols.DATABASE.toString();
model = controllerHelper.setupPage(model,title,subtitle,symbol);
//CountedEntities countedEntities =this.countedEntitiesService.countAll();
//model.addAttribute("countedEntities", countedEntities);

return "application/management";
}


private final CountedEntitiesService countedEntitiesService;


@Autowired
public ApplicationController(CountedEntitiesService countedEntitiesService, ControllerHelper controllerHelper, TwitterProperties twitterProperties) {
this.countedEntitiesService = countedEntitiesService;
this.controllerHelper = controllerHelper;
this.twitterProperties = twitterProperties;
}

private final CountedEntitiesService countedEntitiesService;

private final ControllerHelper controllerHelper;

private final TwitterProperties twitterProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public String domainCountUserprofile2Url(Model model) {
}

private void setUpThisPage(String title,Model model){
controllerHelper.logEnv();
String subtitle = "Counted Entities";
String symbol = Symbols.DATABASE.toString();
model = controllerHelper.setupPage(model,title,subtitle,symbol);
Expand Down
Loading