|
|
@ -61,42 +61,51 @@ public class JobDaily extends JobService {
|
|
|
|
executor.submit(new Runnable() {
|
|
|
|
executor.submit(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
Log.i(Helper.TAG, "Start daily job");
|
|
|
|
try {
|
|
|
|
|
|
|
|
db.beginTransaction();
|
|
|
|
// Cleanup message files
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "Cleanup message files");
|
|
|
|
Log.i(Helper.TAG, "Start daily job");
|
|
|
|
File[] messages = new File(getFilesDir(), "messages").listFiles();
|
|
|
|
|
|
|
|
if (messages != null)
|
|
|
|
// Cleanup message files
|
|
|
|
for (File file : messages)
|
|
|
|
Log.i(Helper.TAG, "Cleanup message files");
|
|
|
|
if (file.isFile()) {
|
|
|
|
File[] messages = new File(getFilesDir(), "messages").listFiles();
|
|
|
|
long id = Long.parseLong(file.getName());
|
|
|
|
if (messages != null)
|
|
|
|
if (db.message().countMessage(id) == 0) {
|
|
|
|
for (File file : messages)
|
|
|
|
Log.i(Helper.TAG, "Cleanup message id=" + id);
|
|
|
|
if (file.isFile()) {
|
|
|
|
if (!file.delete())
|
|
|
|
long id = Long.parseLong(file.getName());
|
|
|
|
Log.w(Helper.TAG, "Error deleting " + file);
|
|
|
|
if (db.message().countMessage(id) == 0) {
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "Cleanup message id=" + id);
|
|
|
|
|
|
|
|
if (!file.delete())
|
|
|
|
|
|
|
|
Log.w(Helper.TAG, "Error deleting " + file);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cleanup attachment files
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "Cleanup attachment files");
|
|
|
|
|
|
|
|
File[] attachments = new File(getFilesDir(), "attachments").listFiles();
|
|
|
|
|
|
|
|
if (attachments != null)
|
|
|
|
|
|
|
|
for (File file : attachments)
|
|
|
|
|
|
|
|
if (file.isFile()) {
|
|
|
|
|
|
|
|
long id = Long.parseLong(file.getName());
|
|
|
|
|
|
|
|
if (db.attachment().countAttachment(id) == 0) {
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "Cleanup attachment id=" + id);
|
|
|
|
|
|
|
|
if (!file.delete())
|
|
|
|
|
|
|
|
Log.w(Helper.TAG, "Error deleting " + file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "Cleanup log");
|
|
|
|
// Cleanup attachment files
|
|
|
|
long before = new Date().getTime() - 24 * 3600 * 1000L;
|
|
|
|
Log.i(Helper.TAG, "Cleanup attachment files");
|
|
|
|
int logs = db.log().deleteLogs(before);
|
|
|
|
File[] attachments = new File(getFilesDir(), "attachments").listFiles();
|
|
|
|
Log.i(Helper.TAG, "Deleted logs=" + logs);
|
|
|
|
if (attachments != null)
|
|
|
|
|
|
|
|
for (File file : attachments)
|
|
|
|
|
|
|
|
if (file.isFile()) {
|
|
|
|
|
|
|
|
long id = Long.parseLong(file.getName());
|
|
|
|
|
|
|
|
if (db.attachment().countAttachment(id) == 0) {
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "Cleanup attachment id=" + id);
|
|
|
|
|
|
|
|
if (!file.delete())
|
|
|
|
|
|
|
|
Log.w(Helper.TAG, "Error deleting " + file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "End daily job");
|
|
|
|
Log.i(Helper.TAG, "Cleanup log");
|
|
|
|
|
|
|
|
long before = new Date().getTime() - 24 * 3600 * 1000L;
|
|
|
|
|
|
|
|
int logs = db.log().deleteLogs(before);
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "Deleted logs=" + logs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "End daily job");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|