use of org.opencastproject.fileupload.api.job.FileUploadJob in project opencast by opencast.
the class FileUploadServiceImpl method cleanOutdatedJobs.
/**
* {@inheritDoc}
*
* @see org.opencastproject.fileupload.api.FileUploadService#cleanOutdatedJobs()
*/
@Override
public void cleanOutdatedJobs() throws IOException {
File[] workRootFiles = workRoot.listFiles();
if (workRootFiles == null) {
logger.trace("No outdated files found in {}", workRoot.getAbsolutePath());
return;
}
for (File dir : workRoot.listFiles()) {
if (dir.getParentFile().equals(workRoot) && dir.isDirectory()) {
try {
// assuming that the dir name is the ID of a job..
String id = dir.getName();
if (!isLocked(id)) {
// ..true if not in cache or job is in cache and not locked
FileUploadJob job = getJob(id);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, -jobMaxTTL);
if (job.lastModified() < cal.getTimeInMillis()) {
FileUtils.forceDelete(dir);
jobCache.remove(id);
logger.info("Deleted outdated job {}", id);
}
}
} catch (Exception e) {
// something went wrong, so we assume the dir is corrupted
// ..and delete it right away
FileUtils.forceDelete(dir);
logger.info("Deleted corrupted job {}", dir.getName());
}
}
}
}
use of org.opencastproject.fileupload.api.job.FileUploadJob in project opencast by opencast.
the class FileUploadServiceImpl method createJob.
// </editor-fold>
/**
* {@inheritDoc}
*
* @see org.opencastproject.fileupload.api.FileUploadService#createJob(String, long, int,
* org.opencastproject.mediapackage.MediaPackage, org.opencastproject.mediapackage.MediaPackageElementFlavor)
*/
@Override
public FileUploadJob createJob(String filename, long filesize, int chunksize, MediaPackage mp, MediaPackageElementFlavor flavor) throws FileUploadException {
FileUploadJob job = new FileUploadJob(filename, filesize, chunksize, mp, flavor);
logger.info("Creating new upload job: {}", job);
try {
// create working dir
File jobDir = getJobDir(job.getId());
FileUtils.forceMkdir(jobDir);
// create empty payload file
ensureExists(getPayloadFile(job.getId()));
// create job file
storeJob(job);
} catch (FileUploadException e) {
deleteJob(job.getId());
throw fileUploadException(Severity.error, "Could not create job file in " + workRoot.getAbsolutePath(), e);
} catch (IOException e) {
deleteJob(job.getId());
throw fileUploadException(Severity.error, "Could not create upload job directory in " + workRoot.getAbsolutePath(), e);
}
return job;
}
Aggregations