{"id":21658211,"url":"https://github.com/scaleway/taskor","last_synced_at":"2025-12-30T01:55:36.979Z","repository":{"id":34870392,"uuid":"174534425","full_name":"scaleway/taskor","owner":"scaleway","description":"Async queued task library for Go","archived":false,"fork":false,"pushed_at":"2024-08-07T08:10:55.000Z","size":130,"stargazers_count":27,"open_issues_count":0,"forks_count":7,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-08-07T11:56:16.692Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scaleway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-03-08T12:31:14.000Z","updated_at":"2024-08-07T08:10:59.000Z","dependencies_parsed_at":"2024-06-20T17:29:11.124Z","dependency_job_id":"ba610eea-3a5f-453a-aa0e-a118f4d5c580","html_url":"https://github.com/scaleway/taskor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaleway%2Ftaskor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaleway%2Ftaskor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaleway%2Ftaskor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaleway%2Ftaskor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scaleway","download_url":"https://codeload.github.com/scaleway/taskor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226304472,"owners_count":17603601,"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","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":[],"created_at":"2024-11-25T09:28:53.945Z","updated_at":"2025-12-30T01:55:36.937Z","avatar_url":"https://github.com/scaleway.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# TASKOR\nTask queue over RabbitMQ lib system.\n\n\n## Installing\nIt is easy to use Taskor.\nIn first time, use `go get` to clone the latest version of the library.\n\n```\ngo get -u github.com/scaleway/taskor\n```\n\nNext, include Taskor in your go file:\n\n```go\nimport \"github.com/scaleway/taskor\"\n```\n\n\n## How it works\n\n### Define a task\n``` go\ntype MyTaskParameter struct {\n\tMyParameter        string\n}\n\nvar MyTask = \u0026taskor.Definition{\n\tName: \"MyTask\",\n\tRun: func(task *task.Task) error {\n\n\t\t// Get Task Param\n\t\tvar param MyTaskParameter\n\t\tif err := task.UnserializeParameter(\u0026param); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tlog.Printf(\"With paramter %s\", param.MyParameter)\n\t\treturn nil\n\t},\n}\n```\n\n### Send a task\n``` go\ntaskManager := taskor.New(runner.RunnerTypeAmqp, config)\ntaskManager.Handle(MyTask)\nMyTask, _ := t.CreateTask(\"MyTask\", param)\nt.Send(MyTask)\n```\n\n### Running worker\n``` go\n// With AMQP driver\nconfig := amqp.NewConfig()\n// Feel free to update your configuration\nconfig.AmqpURL = \"amqp://guest:guest@localhost:5672/\"\nconfig.ExchangeName = \"myexchange\"\nconfig.QueueName = \"taskor_queue\"\nconfig.Concurrency = 5\namqpRunner := amqp.New(config)\ntaskManager := taskor.New(amqpRunner)\ntaskManager.Handle(MyTask)\ntaskManager.RunWorker()\n```\n\n### Example\nSee files in example directory\n\n## Advanced features\n\n### Concurrency\n\nBy default, each worker can only handle one task at the same time (wait for the current task to finish processing before processing the next one). With `Concurrency` property on your runner configuration, you can set a maximum number of workers processing tasks concurrently.\n\nTaskor uses goroutines to run multiple tasks in parallel. To define max number of workers processing tasks at the same time (done at worker initialization):\n``` go\namqpConfig := amqp.NewConfig()\n// set Concurrency on runner configuration\namqpConfig.Concurrency = 5\n\namqpRunner := amqp.New(amqpConfig)\ntaskManager := taskor.New(amqpRunner)\n// ...\ntaskManager.RunWorker()\n```\n\n### Retry\nTo define MaxRetry allowed for a task:\n``` go\nMyTask.MaxRetry = 5\n// or you can do this\nMyTask.SetMaxRetry(5)\n```\n\nTask can be retry if an error is return:\n``` go\nMyTask.RetryOnError = true\n// or you can do this\nMyTask.SetRetryOnError(true)\n```\n\nYou can chain both\n``` go\nMyTask.SetRetryOnError(true).SetMaxRetry(5)\n```\n\nIf you don't want to retry on each error but in a specific case, you just had to return task.ErrTaskRetry as error of your task.\n``` go\nvar MyErrorTask = \u0026task.Definition{\n\tName: \"MyTask\",\n\tRun: func(currentTask *task.Task) error {\n\t\tlog.Printf(\"Task try number %d\", currentTask.CurrentTry)\n\t\t// Return specific error to retry\n\t\tif currentTask.CurrentTry \u003c 20 {\n\t\t\treturn task.ErrTaskRetry # This will perform a retry\n\t\t}\n\t\tlog.Printf(\"Should be iteration number 20\")\n\t\treturn nil\n\t},\n}\n```\n\nTo sum up:\n\n* Taskor doesn't retry a task by default (`MaxRetry: 0`).\n* Taskor retries only if:\n  * `MaxRetry` is defined (use `-1` for infinite retries),\n  * a task returns `task.ErrTaskRetry`,\n  * a task returns any error when `RetryOnError` is `true`.\n\n### LinkError\nLinkError is used to link a task that will be run when a task ending whith error and can't be retry.\n\nTo link a task to an other:\n``` go\nMyTask.SetLinkError(myLinkErrorTask)\n```\n\n### Chain\nChain task is possible adding a child task to an other task. Child will be execute only if parent task is successful\n``` go\nMyTask.AddChild(MyOtherTask)\n```\n\n### ParentTask\nIn case of LinkError or ChildTask, it's possible to access to parent information using task.ParentTask\n``` go\n func(task *task.Task) error {\n\t\tlog.Printf(\"MyParent error was %s\", task.ParentTask.Error)\n\t\treturn nil\n }\n```\n\n### Define a custom logger\nA taskor logger should implement this interface:\n``` go\ntype Logger interface {\n\tDebug(msg string, extraFields map[string]interface{})\n\tInfo(msg string, extraFields map[string]interface{})\n\tWarn(msg string, extraFields map[string]interface{})\n\tError(msg string, extraFields map[string]interface{})\n}\n```\nTo change taskor logger :\n``` go\nimport \ttaskorLogger \"github.com/scaleway/taskor/log\"\n\ntaskorLogger.SetLogger(\u0026LogrusTaskor{})\n```\nSee in example dir to see how to implement logrus\n\n### Get some metrics\n\n``` go\nmetric := taskManager.GetMetrics()\nlog.Printf(\"Task done with error %d\", metric.TaskDoneWithError)\nlog.Printf(\"Task done without error %d\", metric.TaskDoneWithSuccess)\nlog.Printf(\"Task sent %d\", metric.TaskSent)\n```\n\n# Other links:\n* [HowItWorks](doc/HowItWorks.md)\n\n# Dev\n\n## Necessaries packages\n\n```\ngo get github.com/golang/mock/gomock\ngo get github.com/streadway/amqp\n```\n## Run Test\n```\nmake test\n```\n\n## Build\n```\nmake build\n```\n\n## Generate mock\n```\nmake mock\n```\n\n## Import mock\n\nTaskor is mocked in mock, generated by mockgen (https://github.com/golang/mock)\n\nIf you want to mock taskor in your project, you can use this example:\n\n``` go\nimport \"github.com/scaleway/taskor/mock\"\n\nmockTaskor := mock_taskor.NewMockTaskManager(ctrl)\nmockTaskor.EXPECT().Send(gomock.Any()).Times(1).Do(func(taskToRun *taskorTask.Task){\n    ...\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscaleway%2Ftaskor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscaleway%2Ftaskor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscaleway%2Ftaskor/lists"}