当前位置: 首页>>代码示例>>Golang>>正文


Golang App.AsyncAPI方法代码示例

本文整理汇总了Golang中lib/server.App.AsyncAPI方法的典型用法代码示例。如果您正苦于以下问题:Golang App.AsyncAPI方法的具体用法?Golang App.AsyncAPI怎么用?Golang App.AsyncAPI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib/server.App的用法示例。


在下文中一共展示了App.AsyncAPI方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: setupAPIIEPGExclusions

func setupAPIIEPGExclusions(app *server.App) {
	var AsyncAPI = app.AsyncAPI()
	var API = app.API()

	API.GET("/iepg/exclusions/", middleware.EntityAll(IEPGExclusion.Query().Cache(_CacheAllIEPGExclusions)))

	exclusionTask := AsyncAPI.Define("/iepg/exclusions/task/")
	exclusionTask.Queue.Rate = "1/s"
	exclusionTask.Queue.MaxConcurrentRequests = "1"
	exclusionTask.OnTrigger(middleware.Gate("family"))
	exclusionTask.OnMonitor(middleware.Gate("family"))
	exclusionTask.OnProcess(server.AsyncTaskHandler(
		func(req *wcg.Request, t *models.AsyncAPITask) (*models.AsyncAPITaskProgress, error) {
			var list []*pt.IEPG
			records := recentRecordsQuery().MustExecute(req).Data.([]pt.IEPG)
			for i := range records {
				list = append(list, &records[i])
			}
			if err := applyExclusions(req, list); err != nil {
				return nil, err
			}
			IEPG.PutMulti().Cache(_CacheAllIEPGExclusions).MustUpdate(req, list)
			return nil, nil
		},
	))

	API.POST("/iepg/exclusions/",
		middleware.Gate("family"),
		middleware.ParseForm(func(v *validators.FormValidator) {
			v.Field("cid").Required()
			v.Field("sid").Required()
			v.Field("weekday").Required()
			v.Field("title_text").Required()
			v.Field("title_text_type").Required()
		}),
		middleware.EntityPost(IEPGExclusion.Put().Cache(_CacheAllIEPGExclusions)),
	)

	API.DELETE("/iepg/exclusions/:id.json",
		middleware.Gate("family"),
		middleware.EntityDelete(IEPGExclusion.Delete().Cache(_CacheAllIEPGExclusions), "id"))
}
开发者ID:speedland,项目名称:service,代码行数:42,代码来源:api_iepg_exclusions.go

示例2: setupAPITasks

func setupAPITasks(app *server.App) {
	var AsyncAPI = app.AsyncAPI()

	profileSyncTask := AsyncAPI.Define("/tasks/profile/")
	profileSyncTask.Queue.Rate = "1/s"
	profileSyncTask.Queue.MaxConcurrentRequests = "1"
	profileSyncTask.OnTrigger(handlers.AdminGate)
	profileSyncTask.OnMonitor(handlers.AdminGate)
	profileSyncTask.OnProcess(server.AsyncTaskHandler(runTasksProfile))
	profileSyncTask.ScheduleCron(
		"Synchronize profiles",
		"every day 00:10",
	)

	crawlerAmebloEntryListsTask := AsyncAPI.Define("/tasks/crawlers/ameblo/entrylists/")
	crawlerAmebloEntryListsTask.Queue.Rate = "1/s"
	crawlerAmebloEntryListsTask.Queue.MaxConcurrentRequests = "1"
	crawlerAmebloEntryListsTask.OnTrigger(handlers.AdminGate)
	crawlerAmebloEntryListsTask.OnMonitor(handlers.AdminGate)
	crawlerAmebloEntryListsTask.OnProcess(server.AsyncTaskHandler(runTasksCrawlersAmebloEntryLists))
	crawlerAmebloEntryListsTask.ScheduleCron(
		"Crawl Ameblo Entry Lists",
		"every 30 minutes from 18:00 to 23:59",
		"every 30 minutes from 00:00 to 03:00",
		"every 3 hours from 03:00 to 17:59",
	)

	crawlerAmebloPostsTask := AsyncAPI.Define("/tasks/crawlers/ameblo/posts/")
	crawlerAmebloPostsTask.Queue.Rate = "1/s"
	crawlerAmebloPostsTask.Queue.MaxConcurrentRequests = "1"
	crawlerAmebloPostsTask.OnTrigger(handlers.AdminGate)
	crawlerAmebloPostsTask.OnMonitor(handlers.AdminGate)
	crawlerAmebloPostsTask.OnProcess(server.AsyncTaskHandler(runTasksCrawlersAmebloPosts))
	crawlerAmebloPostsTask.ScheduleCron(
		"Crawl Ameblo Posts",
		"every 30 minutes from 19:10 to 23:59",
		"every 30 minutes from 00:10 to 03:10",
		"every 2 hours from 04:10 to 19:09",
	)
}
开发者ID:speedland,项目名称:service,代码行数:40,代码来源:api_tasks.go

示例3: setupAPIIEPGKeywords

func setupAPIIEPGKeywords(app *server.App) {
	var API = app.API()

	API.GET("/iepg/keywords/",
		middleware.EntityAll(IEPGKeyword.Query().Cache(_CacheAllIEPGKeywords)))

	API.POST("/iepg/keywords/",
		middleware.Gate("family"),
		middleware.ParseForm(func(v *validators.FormValidator) {
			v.Field("keyword").Required()
			v.Field("category").Required()
			v.IntField("scope").Required()
		}),
		middleware.EntityPost(IEPGKeyword.Put().Cache(_CacheAllIEPGKeywords)))

	API.DELETE("/iepg/keywords/:id.json",
		middleware.Gate("family"),
		middleware.EntityDelete(IEPGKeyword.Delete().Cache(_CacheAllIEPGKeywords), "id"))

	API.POST("/iepg/keywords/preview/",
		middleware.Gate("family"),
		middleware.ParseForm(func(v *validators.FormValidator) {
			v.Field("keyword").Required()
			v.IntField("scope").Required()
		}),
		server.Handler(
			func(req *wcg.Request) response.Response {
				list, err := crawlKeyword(req, &pt.IEPGKeyword{
					Keyword: req.Form("keyword"),
					Scope:   pt.ParseIEPGCrawlerScope(req.Form("scope")),
				})
				if err != nil {
					return response.InternalServerError(req, err)
				}
				return response.NewJSONResponse(map[string]interface{}{
					"hits": list,
				})
			},
		))

	var AsyncAPI = app.AsyncAPI()

	keywordCrawlTask := AsyncAPI.Define("/iepg/keywords/task/")
	keywordCrawlTask.Queue.Rate = "1/s"
	keywordCrawlTask.Queue.MaxConcurrentRequests = "1"
	keywordCrawlTask.OnTrigger(middleware.Gate("family"))
	keywordCrawlTask.OnMonitor(middleware.Gate("family"))
	keywordCrawlTask.OnProcess(server.AsyncTaskHandler(
		func(req *wcg.Request, t *models.AsyncAPITask) (*models.AsyncAPITaskProgress, error) {
			data := IEPGKeyword.Query().Cache(_CacheAllIEPGKeywords).MustExecute(req).Data
			if data == nil {
				return nil, nil
			}
			var keywords = data.([]pt.IEPGKeyword)
			req.Logger.Infof("Crawling %d keywords", len(keywords))
			for _, key := range keywords {
				list, err := crawlKeyword(req, &key)
				if err != nil {
					return nil, err
				}
				IEPG.PutMulti().Cache(_CacheAllIEPGKeywords).MustUpdate(req, list)
			}
			return nil, nil
		},
	))
	keywordCrawlTask.ScheduleCron(
		"Crawl IEPG keywords",
		"every 1 hours",
	)
}
开发者ID:speedland,项目名称:service,代码行数:70,代码来源:api_iepg_keywords.go


注:本文中的lib/server.App.AsyncAPI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。