{"id":21731506,"url":"https://github.com/altipla-consulting/cloudtasks","last_synced_at":"2025-03-20T23:42:22.235Z","repository":{"id":209723343,"uuid":"724590525","full_name":"altipla-consulting/cloudtasks","owner":"altipla-consulting","description":"Google Cloud Tasks integration with Cloud Run apps.","archived":false,"fork":false,"pushed_at":"2025-03-17T00:20:42.000Z","size":96,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-17T01:27:48.805Z","etag":null,"topics":["cloudrun","cloudtasks","golang","google-cloud"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/altipla-consulting/cloudtasks","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/altipla-consulting.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":"2023-11-28T11:50:36.000Z","updated_at":"2025-03-17T00:20:46.000Z","dependencies_parsed_at":"2025-03-17T01:26:18.218Z","dependency_job_id":"3b2a79d7-1f2c-4804-a2d3-eb4bd8991a46","html_url":"https://github.com/altipla-consulting/cloudtasks","commit_stats":{"total_commits":29,"total_committers":3,"mean_commits":9.666666666666666,"dds":0.06896551724137934,"last_synced_commit":"83e04294c191009c39052a29c562e282e0957ff0"},"previous_names":["altipla-consulting/cloudtasks"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altipla-consulting%2Fcloudtasks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altipla-consulting%2Fcloudtasks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altipla-consulting%2Fcloudtasks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altipla-consulting%2Fcloudtasks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/altipla-consulting","download_url":"https://codeload.github.com/altipla-consulting/cloudtasks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244711934,"owners_count":20497417,"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":["cloudrun","cloudtasks","golang","google-cloud"],"created_at":"2024-11-26T04:26:17.722Z","updated_at":"2025-03-20T23:42:22.228Z","avatar_url":"https://github.com/altipla-consulting.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# cloudtasks\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/altipla-consulting/cloudtasks.svg)](https://pkg.go.dev/github.com/altipla-consulting/cloudtasks)\n\nGoogle Cloud Tasks integration with Cloud Run apps.\n\n\n## Install\n\n```shell\ngo get github.com/altipla-consulting/cloudtasks\n```\n\n\n## Usage\n\n### Declare queues\n\nTo set up the queue system with its corresponding models and APIs, you'll need to call the code declaring the queues from your application's main function and then register the HTTP handler:\n\n```go\nfunc main() {\n  if err := models.ConnectQueues(); err != nil {\n    log.Fatal(err)\n  }\n\n  // Register the queue handlers.\n  http.Handle(cloudtasks.Handler())\n}\n```\n\nIn the `models/queues.go` file:\n\n```go\nvar (\n  QueueFoo cloudtasks.Queue\n  QueueBar cloudtasks.Queue\n)\n\nfunc ConnectQueues() error {\n  QueueFoo = cloudtasks.NewQueue(\"foo\")\n  QueueBar = cloudtasks.NewQueue(\"bar\")\n\n  return nil\n}\n```\n\nQueues manage task consumption rates and the maximum number of concurrent tasks. These are pre-configured in Google Cloud.\n\nA single queue can efficiently process multiple task types. It's recommended to use one queue for similar rate requirements instead of creating multiple queues, as this approach minimizes runtime overhead.\n\n\n### Defining tasks\n\nDefine background tasks within the same package that will execute them. By convention, task functions are named with the suffix `xxFn`, indicating they're background functions. The first argument in `cloudtasks.Func` is a unique string for debugging purposes. Declaring two tasks with the same name will trigger a panic.\n\n```go\nvar fooFn = cloudtasks.Func(\"foo\", func(ctx context.Context, task *cloudtasks.Task) error {\n  var arg int64\n  if err := task.Read(\u0026arg); err != nil {\n    return errors.Trace(err)\n  }\n\n  // ... task content\n\n  return nil\n})\n```\n\nEnsure global task declarations occur during initialization, typically in the init() function.\n\n\n### Task Invocation\n\nInvoke tasks by calling the previously defined functions:\n\n```go\nfunc FooHandler(...) {\n  // ... other code\n\n  var arg int64\n  if err := fooFn.Call(r.Context(), models.QueueFoo, arg); err != nil {\n    return errors.Trace(err)\n  }\n\n  // ... other code\n}\n```\n\nTasks can accept any JSON-serializable data as arguments, excluding structs with private fields or methods. This flexibility allows for various data types, including basic types like numbers and strings, or more complex structures needed for task execution.\n\n\n### External task invocation\n\nInvoke tasks of external applications with our helper that has retry and authorization built-in:\n\n```go\nfunc FooHandler(w http.ResponseWriter, r *http.Request) error {\n  // ... other code\n\n  task := \u0026cloudtasks.ExternalTask{\n    URL: \"https://foo-service-9omj3qcv6b-ew.a.run.app/myurl\",\n    Payload: arg,\n  }\n  if err := models.QueueFoo.SendExternal(r.Context(), task); err != nil {\n    return errors.Trace(err)\n  }\n\n  // ... other code\n}\n```\n\n## Upgrades\n\n### v0 -\u003e v1\n\n`cloudtasks.NewQueue()` now needs one less parameter. The first parameter with the Cloud Run URL is now deterministically guessed from the environment and can be completely removed.\n\n\n## Contributing\n\nYou can make pull requests or create issues in GitHub. Any code you send should be formatted using `make gofmt`.\n\n\n## License\n\n[MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltipla-consulting%2Fcloudtasks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faltipla-consulting%2Fcloudtasks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltipla-consulting%2Fcloudtasks/lists"}