{"id":34204188,"url":"https://github.com/shiningrush/dolphin","last_synced_at":"2026-03-10T21:32:17.628Z","repository":{"id":57537872,"uuid":"142833659","full_name":"ShiningRush/dolphin","owner":"ShiningRush","description":"A lightweight data warehouse solution to solve problems about complex query in microservices, such as data statistics and query on multiple micro services.","archived":false,"fork":false,"pushed_at":"2023-02-25T03:13:12.000Z","size":1426,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-21T09:49:26.643Z","etag":null,"topics":["background","datawarehouse"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShiningRush.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-30T06:24:10.000Z","updated_at":"2024-02-11T01:56:36.000Z","dependencies_parsed_at":"2024-06-20T03:17:38.833Z","dependency_job_id":"fc64ac61-2d3e-4259-be00-5c0ae8c36aed","html_url":"https://github.com/ShiningRush/dolphin","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ShiningRush/dolphin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShiningRush%2Fdolphin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShiningRush%2Fdolphin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShiningRush%2Fdolphin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShiningRush%2Fdolphin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShiningRush","download_url":"https://codeload.github.com/ShiningRush/dolphin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShiningRush%2Fdolphin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27755915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-15T02:00:09.782Z","response_time":96,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["background","datawarehouse"],"created_at":"2025-12-15T19:05:15.488Z","updated_at":"2025-12-15T19:05:20.272Z","avatar_url":"https://github.com/ShiningRush.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dolphin\n[![Go Report Card](https://goreportcard.com/badge/github.com/ShiningRush/dolphin)](https://goreportcard.com/report/github.com/ShiningRush/dolphin)\n\ndolphin 是一个轻量级的任务框架，主要用来解决微服务中那些复杂的跨服务统计查询与传统企业应用中的一些统计报表，你也可以把它当作一个普通的后台任务管理框架。\n\n## Get Started\n\n### 安装\n\n```\ngo get -u github.com/ShiningRush/dolphin\n```\n\n### 使用\n\n```\ntype testBatch struct {\n\tName string\n}\n\nfunc (c *testBatch) GetName() string {\n\treturn c.Name\n}\n\nfunc (c *testBatch) Begin(e *task.EtlTask) error {\n\tlog.Println(c.Name)\n\treturn nil\n}\n\nfunc (c *testBatch) Reset() error {\n\treturn nil\n}\n\nfunc main() {\n  oneShotTask := task.NewTask(\u0026testBatch{Name: \"oneShotTask\"})\n  planTask := task.NewTask(\u0026testBatch{Name: \"planTask\"})\n  planTask.PlanTime = \"0-59/5 * * * * *\" \n  if err := dolphin.Add(oneShotTask).Add(planTask).Build(); err != nil {\n\t\tpanic(\"build faild!\")\n\t}\n  \n  ....\n}\n\n```\n\n上面的代码没有贴完全，但在执行完 Build 之后你应该能够看到 OneShotTask 的输出, 并且每隔 5 秒你就能看到 PlanTask的输出\n\n## 工作方式\ndolphin 主要由任务(task)组成，与普通的后台任务处理不同在于任务是由批处理(batch)与同步器(syncer)组成。\n\n### 任务(Task)\n\ndolphin 的核心角色，与正常后台任务的控制没有太大区别。\n任务可以分成两类\n\n- OneShot\n- Plan\n\n如字面意义上所表现的，OneShot任务只会执行一次，而Plan会定时执行。\n\n同时你也可以指定任务在指定的时刻运行，只需要设置任务的 `PlanTime`属性\n\n### 批处理(Batch)\n\n批处理是任务执行所运行的动作，批处理必须实现以下接口\n\n```\n// Batch interface\ntype Batch interface {\n\tGetName() string\n\tBegin(t *EtlTask) error\n\tReset() error\n}\n```\n\nGetName 所取得的名字会作为任务的唯一ID，不允许使用相同的名字。\nBegin 是任务运行时会执行的一些动作\nReset 可以执行一些消除任务副作用的动作，比如某个数据表每天会全量更新，那么就需要在Begin之前先Reset老的数据\n\n\u003e ### 提示\n\u003e 可以通过设置Task的ResetBeforeBegin属性来决定是否在Begin前Reset\n\n\n### 同步器(syncer)\n\n这是dolphin与其他任务调度框架不同的最大之处，为了解决构建数据仓库中实时同步的问题，我们需要一些同步器来同步实时数据到数据仓库。\n同步器需要实现以下接口。\n\n```\n// Syncer must be singleton\ntype Syncer interface {\n\tStart()\n\tStop()\n}\n```\n\n注意上面的提示：同步器最好是单例的，意味着你在处理更新信号时，要保证使用同一个同步器。\n同步器会在任务执行时会调用Start方法，在任务执行完毕后调用Stop方法。\n\ndolphin内置了一个阻塞式的同步器，它提供了一个CheckStatus方法，这个方法会在任务执行时阻塞，一直到任务执行完毕才释放。\n使用阻塞同步器只要在你的自定义同步器里组合`syncer.BlockSyncer`，同时在同步器执行时调用 CheckStatus 就行了。\n\n```\n// Tradesyncer will handle changes in trade table\ntype TestSyncer struct {\n\tsyncer.BlockSyncer\n}\n\n```\n\n## 仪表盘\n\ndolphin提供了一个Dashboard查看各个任务的执行状态和一些基本的控制，如果要启动它，使用以下的代码：\n\n```\nimport \"github.com/ShiningRush/dolphin/dashserver\"\n\nfunc XXX(){\n  hs := dashserver.Start(\"0.0.0.0:6060\")\n  ....\n  if err := hs.Shutdown(nil); err != nil {\n\t\t\t\tlog.Println(\"Get error when shutdown dashserver\" + err.Error())\n\t\t\t\treturn err\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiningrush%2Fdolphin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshiningrush%2Fdolphin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiningrush%2Fdolphin/lists"}