diff --git a/CHANGELOG.md b/CHANGELOG.md index b7e21ad..9dc7401 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,16 +4,8 @@ ## [Unreleased] ### Added +- batch submit event log -### Changed - -### Deprecated - -### Removed - -### Fixed - -### Security ## [0.0.6] ### Added - add plugin vendor diff --git a/gradle.properties b/gradle.properties index 1954aa8..d86e56a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/kotlin/com/github/si9ma/codetimejetbrains/listeners/CodeTimeProjectManagerListener.kt b/src/main/kotlin/com/github/si9ma/codetimejetbrains/listeners/CodeTimeProjectManagerListener.kt index 0d6c238..62be541 100644 --- a/src/main/kotlin/com/github/si9ma/codetimejetbrains/listeners/CodeTimeProjectManagerListener.kt +++ b/src/main/kotlin/com/github/si9ma/codetimejetbrains/listeners/CodeTimeProjectManagerListener.kt @@ -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") @@ -43,10 +45,15 @@ class CodeTimeProjectManagerListener : ProjectManagerListener { Timer().scheduleAtFixedRate( timerTask { if (Queue.logQueue.size > 0) { - while (true) { - val event: MutableMap = Queue.logQueue.poll() ?: break - submitEventLog(project, uuid, event) + val events: MutableList> = 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), @@ -63,20 +70,24 @@ class CodeTimeProjectManagerListener : ProjectManagerListener { ) } - private fun submitEventLog(project: Project, uuid: String, event: MutableMap) { + private fun submitEventLog(project: Project, uuid: String, events: MutableList>) { 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) {