prepairing infrastructure for scheduler immediate start feature
This commit is contained in:
parent
2e73d733f2
commit
fdd0117d6f
campcaster/src
modules/eventScheduler
products/scheduler/src
|
@ -89,6 +89,17 @@ class EventContainerInterface
|
|||
*/
|
||||
virtual Ptr<ScheduledEventInterface>::Ref
|
||||
getNextEvent(Ptr<ptime>::Ref when) throw () = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Return current event
|
||||
*
|
||||
* @param
|
||||
* @return the first event to schedule at this point in time
|
||||
* may be a reference to 0, if there are no known events at this time
|
||||
*/
|
||||
virtual Ptr<ScheduledEventInterface>::Ref
|
||||
getCurrentEvent() throw () = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -95,6 +95,29 @@ SchedulerThread :: getNextEvent(Ptr<ptime>::Ref when) throw ()
|
|||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Get the next event from the eventContainer
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerThread :: getCurrentEvent() throw ()
|
||||
{
|
||||
//DEBUG_FUNC_INFO
|
||||
|
||||
nextEvent = eventContainer->getCurrentEvent();
|
||||
if (nextEvent.get()) {
|
||||
nextEventTime = TimeConversion::now();
|
||||
nextInitTime.reset(new ptime(*nextEventTime));
|
||||
nextEventEnd.reset(new ptime(*nextEvent->getScheduledTime()
|
||||
+ *nextEvent->eventLength()));
|
||||
debug() << "::getCurrentEvent() - nextInitTime: "
|
||||
<< to_simple_string(*nextInitTime) << endl;
|
||||
debug() << " - nextEventTime: "
|
||||
<< to_simple_string(*nextEventTime) << endl;
|
||||
debug() << " - nextEventEnd: "
|
||||
<< to_simple_string(*nextEventEnd) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The main execution body of the thread.
|
||||
|
@ -158,7 +181,8 @@ SchedulerThread :: run(void) throw ()
|
|||
//DEBUG_FUNC_INFO
|
||||
|
||||
shouldRun = true;
|
||||
getNextEvent(TimeConversion::now());
|
||||
// getCurrentEvent();
|
||||
getNextEvent();
|
||||
|
||||
while (shouldRun) {
|
||||
Ptr<ptime>::Ref start = TimeConversion::now();
|
||||
|
|
|
@ -153,6 +153,14 @@ class SchedulerThread : public virtual RunnableInterface
|
|||
void
|
||||
getNextEvent(Ptr<ptime>::Ref when) throw ();
|
||||
|
||||
/**
|
||||
* Get the current event.
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
void
|
||||
getCurrentEvent() throw ();
|
||||
|
||||
/**
|
||||
* Tell if the specified time falls within now and the next
|
||||
* waking up. Basically tells if it is within now and
|
||||
|
|
|
@ -98,3 +98,23 @@ PlaylistEventContainer :: getNextEvent(Ptr<ptime>::Ref when) throw ()
|
|||
return event;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Return the first scheduled event after the specified timepoint
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<ScheduledEventInterface>::Ref
|
||||
PlaylistEventContainer :: getCurrentEvent() throw ()
|
||||
{
|
||||
Ptr<ScheduleEntry>::Ref entry = schedule->getCurrentEntry();
|
||||
Ptr<PlaylistEvent>::Ref event;
|
||||
|
||||
if (entry.get()) {
|
||||
event.reset(new PlaylistEvent(sessionId,
|
||||
audioPlayer,
|
||||
storage,
|
||||
playLog,
|
||||
entry));
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,6 +142,17 @@ class PlaylistEventContainer : public virtual EventContainerInterface
|
|||
*/
|
||||
virtual Ptr<ScheduledEventInterface>::Ref
|
||||
getNextEvent(Ptr<ptime>::Ref when) throw ();
|
||||
|
||||
|
||||
/**
|
||||
* Return current event
|
||||
*
|
||||
* @param
|
||||
* @return the first event to schedule at this point in time
|
||||
* may be a reference to 0, if there are no known events at this time
|
||||
*/
|
||||
virtual Ptr<ScheduledEventInterface>::Ref
|
||||
getCurrentEvent() throw ();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -161,6 +161,16 @@ const std::string PostgresqlSchedule::getNextEntryStmt =
|
|||
"SELECT id, playlist, starts, ends FROM schedule WHERE ? < starts "
|
||||
"ORDER BY starts";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The SQL statement for querying current scheduled entry
|
||||
* The parameters for this call are: from
|
||||
* and returns the properties: id, playlist, starts, ends for the current
|
||||
* schedule entry
|
||||
*----------------------------------------------------------------------------*/
|
||||
const std::string PostgresqlSchedule::getCurrentEntryStmt =
|
||||
"SELECT id, playlist, starts, ends FROM schedule WHERE starts <= ? AND ? < ends "
|
||||
"ORDER BY starts";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The SQL statement for querying if a schedule entry exists.
|
||||
* Expects a single argument, the id of the schedule to check.
|
||||
|
@ -542,6 +552,53 @@ PostgresqlSchedule :: getNextEntry(Ptr<ptime>::Ref fromTime)
|
|||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Get current schedule entry
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<ScheduleEntry>::Ref
|
||||
PostgresqlSchedule :: getCurrentEntry()
|
||||
throw ()
|
||||
{
|
||||
Ptr<Connection>::Ref conn;
|
||||
Ptr<ScheduleEntry>::Ref result;
|
||||
|
||||
try {
|
||||
conn = cm->getConnection();
|
||||
Ptr<Timestamp>::Ref timestamp;
|
||||
Ptr<PreparedStatement>::Ref pstmt(conn->prepareStatement(
|
||||
getCurrentEntryStmt));
|
||||
timestamp = Conversion::ptimeToTimestamp(TimeConversion::now(),
|
||||
Conversion::roundDown);
|
||||
|
||||
pstmt->setTimestamp(1, *timestamp);
|
||||
pstmt->setTimestamp(2, *timestamp);
|
||||
|
||||
Ptr<ResultSet>::Ref rs(pstmt->executeQuery());
|
||||
if (rs->next()) {
|
||||
Ptr<UniqueId>::Ref id(new UniqueId(rs->getLong(1)));
|
||||
Ptr<UniqueId>::Ref playlistId(new UniqueId(rs->getLong(2)));
|
||||
|
||||
*timestamp = rs->getTimestamp(3);
|
||||
Ptr<ptime>::Ref startTime = Conversion::timestampToPtime(timestamp);
|
||||
|
||||
*timestamp = rs->getTimestamp(4);
|
||||
Ptr<ptime>::Ref endTime = Conversion::timestampToPtime(timestamp);
|
||||
|
||||
result.reset(new ScheduleEntry(id, playlistId, startTime, endTime));
|
||||
}
|
||||
|
||||
cm->returnConnection(conn);
|
||||
} catch (std::exception &e) {
|
||||
if (conn) {
|
||||
cm->returnConnection(conn);
|
||||
}
|
||||
// TODO: report error
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Tell if a schedule entry exists.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -154,6 +154,11 @@ class PostgresqlSchedule : public Configurable,
|
|||
*/
|
||||
static const std::string getNextEntryStmt;
|
||||
|
||||
/**
|
||||
* The SQL statement for getting current schedule entry
|
||||
*/
|
||||
static const std::string getCurrentEntryStmt;
|
||||
|
||||
/**
|
||||
* The SQL statement for telling if a schedule entry exists.
|
||||
*/
|
||||
|
@ -320,6 +325,17 @@ class PostgresqlSchedule : public Configurable,
|
|||
getNextEntry(Ptr<ptime>::Ref fromTime)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* Return current schedule entry
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return the first schedule entry at this point in time
|
||||
*/
|
||||
virtual Ptr<ScheduleEntry>::Ref
|
||||
getCurrentEntry()
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* Tell if a schedule entry exists by the give name.
|
||||
*
|
||||
|
|
|
@ -178,6 +178,19 @@ class ScheduleInterface
|
|||
throw ()
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* Return the current schedule entry.
|
||||
*
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return the current schedule entry
|
||||
*/
|
||||
virtual Ptr<ScheduleEntry>::Ref
|
||||
getCurrentEntry()
|
||||
throw ()
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* Tell if a schedule entry exists by the give name.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue