This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun doWork(): Result { | |
val logs: List<RemoteLog> = appDatabase.remoteLogsDao().getLogs(FLUSH_CHUNK_SIZE) | |
val success: Boolean= someNetworkingManager.sendLogs(logs) | |
if(success) { | |
appDatabase.remoteLogsDao().deleteOldLogs(FLUSH_CHUNK_SIZE) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun scheduleWorker() { | |
val constraints = Constraints.Builder() | |
.setRequiredNetworkType(NetworkType.CONNECTED) | |
.build() | |
val request = | |
PeriodicWorkRequestBuilder<FlushLogsWorker>( | |
repeatInterval = CHUNK_SENDING_TIMEOUT_MINUTES, | |
repeatIntervalTimeUnit = TimeUnit.MINUTES | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun log(message: String, tag: String, logLevel: Int) { | |
//Create a RemoteLog object | |
val remoteLog = RemoteLog( | |
message = message, | |
tag = tag, | |
timestamp = DateTime.now(), | |
logLevel = logLevel | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface RemoteLogger { | |
fun log( | |
message: String, | |
tag: String, | |
logLevel: Int | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Dao | |
interface RemoteLogsDao { | |
@Insert(onConflict = OnConflictStrategy.REPLACE) | |
fun insertLog(remoteLog: RemoteLog) | |
@Query("SELECT COUNT(*) FROM $REMOTE_LOGS_TABLE_NAME") | |
fun getLogsCount(): Long | |
@Query("SELECT * FROM $REMOTE_LOGS_TABLE_NAME ORDER BY timestamp ASC LIMIT :count") |