本文整理汇总了Golang中github.com/ajvb/kala/job.JobCache.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang JobCache.Get方法的具体用法?Golang JobCache.Get怎么用?Golang JobCache.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ajvb/kala/job.JobCache
的用法示例。
在下文中一共展示了JobCache.Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: HandleListJobStatsRequest
// HandleListJobStatsRequest is the handler for getting job-specific stats
// /api/v1/job/stats/{id}
func HandleListJobStatsRequest(cache job.JobCache) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
j, err := cache.Get(id)
if err != nil {
log.Error("Error occured when trying to get the job you requested.")
w.WriteHeader(http.StatusNotFound)
return
}
if j == nil {
w.WriteHeader(http.StatusNotFound)
return
}
resp := &ListJobStatsResponse{
JobStats: j.Stats,
}
w.Header().Set(contentType, jsonContentType)
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(resp); err != nil {
log.Error("Error occured when marshalling response: %s", err)
return
}
}
}
示例2: HandleJobRequest
// HandleJobRequest routes requests to /api/v1/job/{id} to either
// handleDeleteJob if its a DELETE or handleGetJob if its a GET request.
func HandleJobRequest(cache job.JobCache, db job.JobDB) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
j, err := cache.Get(id)
if err != nil {
log.Error("Error occured when trying to get the job you requested.")
w.WriteHeader(http.StatusNotFound)
return
}
if j == nil {
w.WriteHeader(http.StatusNotFound)
return
}
if r.Method == "DELETE" {
err = j.Delete(cache, db)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
} else {
w.WriteHeader(http.StatusNoContent)
}
} else if r.Method == "GET" {
handleGetJob(w, r, j)
}
}
}
示例3: HandleStartJobRequest
// HandleStartJobRequest is the handler for manually starting jobs
// /api/v1/job/start/{id}
func HandleStartJobRequest(cache job.JobCache) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
j, err := cache.Get(id)
if err != nil {
log.Error("Error occured when trying to get the job you requested.")
w.WriteHeader(http.StatusNotFound)
return
}
if j == nil {
w.WriteHeader(http.StatusNotFound)
return
}
j.Run(cache)
w.WriteHeader(http.StatusNoContent)
}
}