Skip to content

Commit

Permalink
Add scheduled task to update show statuses (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
akim-ruslanov committed May 17, 2022
1 parent 101cdbf commit b414abc
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cuebot/src/main/java/com/imageworks/spcue/dao/ShowDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,11 @@ public interface ShowDao {
* @param emails
*/
void updateShowCommentEmail(ShowInterface s, String[] emails);

/**
* Scheduled task to update shows. Set show as inactive if it has at
* least 1 job in job_history service th
*/
void updateShowsStatus();
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.RowMapper;
Expand All @@ -35,6 +40,8 @@
import com.imageworks.spcue.util.SqlUtil;

public class ShowDaoJdbc extends JdbcDaoSupport implements ShowDao {
@Autowired
private Environment env;

private static final RowMapper<ShowEntity> SHOW_MAPPER =
new RowMapper<ShowEntity>() {
Expand Down Expand Up @@ -228,6 +235,36 @@ public void updateShowCommentEmail(ShowInterface s, String[] email) {
StringUtils.join(email, ","), s.getShowId());
}

@Override
public void updateShowsStatus() {
Stream<String> protectedShowsRaw = Arrays.stream(env.getProperty("protected_shows", String.class).split(","));
String protectedShows = protectedShowsRaw.map(show -> "'" + show + "'")
.collect(Collectors.joining(","));
getJdbcTemplate().update("UPDATE " +
"show " +
"SET " +
"b_active=false " +
"WHERE " +
"pk_show NOT IN (" +
"SELECT " +
"pk_show " +
"FROM (" +
"SELECT " +
"pk_show, count(pk_job) " +
"FROM " +
"job_history " +
"WHERE " +
"(DATE_PART('days', NOW()) - DATE_PART('days', dt_last_modified)) < 30 " +
"GROUP BY " +
"pk_show " +
"HAVING COUNT(pk_job)>0 " +
") pk_show" +
") " +
"AND " +
"str_name NOT IN (?)",
protectedShows);
}

@Override
public void updateFrameCounters(ShowInterface s, int exitStatus) {
String col = "int_frame_success_count = int_frame_success_count + 1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public interface AdminManager {
ShowEntity getShowEntity(String id);
void setShowActive(ShowInterface show, boolean value);
void updateShowCommentEmail(ShowInterface s, String[] emails);
void updateShowsStatus();

/*
* Facilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public void updateShowCommentEmail(ShowInterface s, String[] emails) {
showDao.updateShowCommentEmail(s, emails);
}

@Override
public void updateShowsStatus() {
showDao.updateShowsStatus();
}

public SubscriptionInterface createSubscription(SubscriptionEntity sub) {
subscriptionDao.insertSubscription(sub);
return sub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,19 @@
<property name="repeatInterval" value="43200000" />
</bean>

<bean id="updateShowsStatus" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="adminManager" />
<property name="targetMethod" value="updateShowsStatus" />
</bean>

<bean id="updateShowsStatusTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="updateShowsStatus" />
<!-- delay 60 seconds -->
<property name="startDelay" value="60000" />
<!-- repeat once a week -->
<property name="repeatInterval" value="604800000" />
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy">
<property name="waitForJobsToCompleteOnShutdown"><value>false</value></property>
<property name="triggers">
Expand All @@ -557,6 +570,7 @@
<ref bean="dispatchQueueSchedule" />
<ref bean="manageQueueSchedule" />
<ref bean="killQueueSchedule" />
<ref bean="updateShowsStatusTrigger"/>
</list>
</property>
</bean>
Expand Down
3 changes: 3 additions & 0 deletions cuebot/src/main/resources/opencue.properties
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,6 @@ maintenance.auto_delete_down_hosts=false

# Set hostname/IP of the smtp host. Will be used for mailing
smtp_host=smtp

# These shows won't be deactivated by the scheduled tasks
protected_shows=pipe,swtest,edu

0 comments on commit b414abc

Please sign in to comment.