mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
Plugin updating is executed asynchronously by Quartz Scheduler
This commit is contained in:
@@ -87,25 +87,6 @@ object PluginSystem {
|
||||
case class RepositoryMenu(label: String, name: String, url: String, icon: String, condition: Context => Boolean)
|
||||
case class Action(path: String, function: (HttpServletRequest, HttpServletResponse) => Any)
|
||||
|
||||
/**
|
||||
* Clone or pull all plugin repositories
|
||||
*
|
||||
* TODO Support plugin repository access through the proxy server
|
||||
*/
|
||||
def updateAllRepositories(): Unit = {
|
||||
repositories.foreach { repository =>
|
||||
val dir = getPluginCacheDir()
|
||||
val repo = new java.io.File(dir, repository.id)
|
||||
if(repo.exists){
|
||||
// pull if the repository is already cloned
|
||||
Git.open(repo).pull().call()
|
||||
} else {
|
||||
// clone if the repository is not exist
|
||||
Git.cloneRepository().setURI(repository.url).setDirectory(repo).call()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the plugin is updatable.
|
||||
*/
|
||||
@@ -126,8 +107,6 @@ object PluginSystem {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO This is a test
|
||||
// addGlobalMenu("Google", "http://www.google.co.jp/", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAEvwAABL8BkeKJvAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAIgSURBVEiJtdZNiI1hFAfw36ORhSFFPgYLszOKJAsWRLGzks1gYyFZKFs7C7K2Y2XDRiwmq9kIJWQjJR9Tk48xRtTIRwjH4p473nm99yLNqdNTz/mf//+555x7ektEmEmbNaPs6OkUKKX0YBmWp6/IE8bwIs8xjEfEt0aiiJBl6sEuXMRLfEf8pX/PnIvJ0TPFWxE4+w+Ef/Kzbd5qDx5l8H8tkku7LG17gH7sxWatevdhEUoXsjda5RnDTZzH6jagtMe0lHIa23AJw3iOiSRZlmJ9mfcyfTzFl2AldmI3rkbEkbrAYKrX7S1eVRyWVnxhQ87eiLjQ+o2/mtyve+PuYy3W4+EfsP2/TVGKTHRI+Iz9Fdx8XOmAnZjGWRMYqoF/4ESW4hpOYk1iZ2WsLjDUTeBYBfgeuyux2XiNT5hXud+DD5W8Y90EtifoSfultfjx7MVtrKzcr8No5m7vJtCLx1hQJ8/4IZzClpyoy5ibsYUYQW81Z9o2jYgPeKr15+poEXE9+1XF9WIkOaasaV2P4k4pZUdDbEm+VEQcjIgtEfGxlLIVd/Gs6TX1MhzQquU3HK1t23f4IsuS94fxNXMO/MbXIDBg+tidw5yMbcCmylSdqWEH/kagYLKWeAt9Fcxi3KhhJuXq6SqQBMO15NDalvswmLWux4cbuToIbMS9BpJOfg8bm7imtmmTlVJWaa3hpnU9nufziBjtyDHTny0/AaA7Qnb4AM4aAAAAAElFTkSuQmCC")
|
||||
// { context => context.loginAccount.isDefined }
|
||||
|
||||
66
src/main/scala/plugin/PluginUpdateJob.scala
Normal file
66
src/main/scala/plugin/PluginUpdateJob.scala
Normal file
@@ -0,0 +1,66 @@
|
||||
package plugin
|
||||
|
||||
import util.Directory._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.quartz.{Scheduler, JobExecutionContext, Job}
|
||||
import org.quartz.JobBuilder._
|
||||
import org.quartz.TriggerBuilder._
|
||||
import org.quartz.SimpleScheduleBuilder._
|
||||
|
||||
class PluginUpdateJob extends Job {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(classOf[PluginUpdateJob])
|
||||
private var failedCount = 0
|
||||
|
||||
/**
|
||||
* Clone or pull all plugin repositories
|
||||
*
|
||||
* TODO Support plugin repository access through the proxy server
|
||||
*/
|
||||
override def execute(context: JobExecutionContext): Unit = {
|
||||
try {
|
||||
if(failedCount > 3){
|
||||
logger.error("Skip plugin information updating because failed count is over limit")
|
||||
} else {
|
||||
logger.info("Start plugin information updating")
|
||||
PluginSystem.repositories.foreach { repository =>
|
||||
logger.info(s"Updating ${repository.id}: ${repository.url}...")
|
||||
val dir = getPluginCacheDir()
|
||||
val repo = new java.io.File(dir, repository.id)
|
||||
if(repo.exists){
|
||||
// pull if the repository is already cloned
|
||||
Git.open(repo).pull().call()
|
||||
} else {
|
||||
// clone if the repository is not exist
|
||||
Git.cloneRepository().setURI(repository.url).setDirectory(repo).call()
|
||||
}
|
||||
}
|
||||
logger.info("End plugin information updating")
|
||||
}
|
||||
} catch {
|
||||
case e: Exception => {
|
||||
failedCount = failedCount + 1
|
||||
logger.error("Failed to update plugin information", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object PluginUpdateJob {
|
||||
|
||||
def schedule(scheduler: Scheduler): Unit = {
|
||||
val job = newJob(classOf[PluginUpdateJob])
|
||||
.withIdentity("pluginUpdateJob")
|
||||
.build()
|
||||
|
||||
val trigger = newTrigger()
|
||||
.withIdentity("pluginUpdateTrigger")
|
||||
.startNow()
|
||||
.withSchedule(simpleSchedule().withIntervalInHours(24).repeatForever())
|
||||
.build()
|
||||
|
||||
scheduler.scheduleJob(job, trigger)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user