Skip to content

Commit

Permalink
feat: batch submit event log
Browse files Browse the repository at this point in the history
  • Loading branch information
si9ma committed Jan 14, 2021
1 parent f33dae6 commit 704bbe2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
10 changes: 1 addition & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@

## [Unreleased]
### Added
- batch submit event log

### Changed

### Deprecated

### Removed

### Fixed

### Security
## [0.0.6]
### Added
- add plugin vendor
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = com.github.si9ma.codetimejetbrains
pluginName_ = codetime
pluginVersion = 0.0.6
pluginVersion = 0.0.7
pluginSinceBuild = 193
pluginUntilBuild = 203.*
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import java.util.UUID
import kotlin.concurrent.timerTask

const val TIMER_DELAY = 100
const val TIMER_PERIOD = 100
const val TIMER_PERIOD = 30 * 1000
const val PLUGIN_NAME = "codetime-jetbrains"
const val PLUGIN_VERSION = "0.0.7"

class CodeTimeProjectManagerListener : ProjectManagerListener {
private val log: Logger = Logger.getInstance("CodeTime")
Expand All @@ -43,10 +45,15 @@ class CodeTimeProjectManagerListener : ProjectManagerListener {
Timer().scheduleAtFixedRate(
timerTask {
if (Queue.logQueue.size > 0) {
while (true) {
val event: MutableMap<String, Any> = Queue.logQueue.poll() ?: break
submitEventLog(project, uuid, event)
val events: MutableList<MutableMap<String, Any>> = ArrayList()
val total = Queue.logQueue.size
var idx = 0
while (idx < total) {
val event = Queue.logQueue.poll()
events.add(event)
idx++
}
submitEventLog(project, uuid, events)
}
},
toLong(TIMER_DELAY),
Expand All @@ -63,20 +70,24 @@ class CodeTimeProjectManagerListener : ProjectManagerListener {
)
}

private fun submitEventLog(project: Project, uuid: String, event: MutableMap<String, Any>) {
private fun submitEventLog(project: Project, uuid: String, events: MutableList<MutableMap<String, Any>>) {
val projectPath: String? = project.guessProjectDir()?.path
val absoluteFile = event["absoluteFile"]
event["project"] = project.name
event["platform"] = System.getProperty("os.name")
event["platformVersion"] = System.getProperty("os.version")
event["platformArch"] = System.getProperty("os.arch")
event["editor"] = ApplicationNamesInfo.getInstance().fullProductName
event["editorVersion"] = ApplicationInfo.getInstance().fullVersion
event["sessionID"] = uuid
event["relativeFile"] = projectPath?.let { absoluteFile.toString().removePrefix(it) } ?: ""
Fuel.post("https://codetime-api.datreks.com/eventLog")
for (event in events) {
val absoluteFile = event["absoluteFile"]
event["project"] = project.name
event["platform"] = System.getProperty("os.name")
event["platformVersion"] = System.getProperty("os.version")
event["platformArch"] = System.getProperty("os.arch")
event["editor"] = ApplicationNamesInfo.getInstance().fullProductName
event["editorVersion"] = ApplicationInfo.getInstance().fullVersion
event["sessionID"] = uuid
event["plugin"] = PLUGIN_NAME
event["pluginVersion"] = PLUGIN_VERSION
event["relativeFile"] = projectPath?.let { absoluteFile.toString().removePrefix(it) } ?: ""
}
Fuel.post("https://codetime-api.datreks.com/batchEventLog")
.header("token", PluginStateComponent.instance.state.token)
.jsonBody(Klaxon().toJsonString(event)).responseJson() { _, _, result ->
.jsonBody(Klaxon().toJsonString(events)).responseJson() { _, _, result ->
result.fold(
success = {
if (PluginStateComponent.instance.state.debug) {
Expand Down

0 comments on commit 704bbe2

Please sign in to comment.