@Transactional(readOnly = false)
public ScheduleResult scheduleUpdate(final ApiKey apiKey,
int objectTypes, UpdateType updateType, long timeScheduled,
String... jsonParams) {
UpdateWorkerTask updateScheduled = getUpdateWorkerTask(apiKey, objectTypes);
ScheduleResult scheduleResult = null;
if (updateScheduled==null) {
UpdateWorkerTask updateWorkerTask = new UpdateWorkerTask();
updateWorkerTask.guestId = apiKey.getGuestId();
updateWorkerTask.connectorName = apiKey.getConnector().getName();
updateWorkerTask.apiKeyId = apiKey.getId();
updateWorkerTask.objectTypes = objectTypes;
updateWorkerTask.updateType = updateType;
updateWorkerTask.status = Status.SCHEDULED;
updateWorkerTask.timeScheduled = timeScheduled;
updateWorkerTask.serverUUID = UNCLAIMED;
if (jsonParams!=null&&jsonParams.length>0)
updateWorkerTask.jsonParams = jsonParams[0];
em.persist(updateWorkerTask);
long now = System.currentTimeMillis();
scheduleResult = new ScheduleResult(apiKey.getId(), apiKey.getConnector().getName(), objectTypes,
timeScheduled <= now
? ScheduleResult.ResultType.SCHEDULED_UPDATE_IMMEDIATE
: ScheduleResult.ResultType.SCHEDULED_UPDATE_DEFERRED,
timeScheduled);
} else {
scheduleResult = new ScheduleResult(apiKey.getId(), apiKey.getConnector().getName(), objectTypes,
ScheduleResult.ResultType.ALREADY_SCHEDULED,
updateScheduled.timeScheduled);
}
StringBuilder sb = new StringBuilder("module=updateQueue component=connectorUpdateService action=scheduleUpdate")
.append(" guestId=").append(apiKey.getGuestId())