{"id":26145090,"url":"https://github.com/sky93/taskflow","last_synced_at":"2026-04-25T09:02:14.992Z","repository":{"id":281194245,"uuid":"944513416","full_name":"sky93/taskflow","owner":"sky93","description":"⏳ Taskflow is a lightweight Go library for running background jobs from a database queue table.","archived":false,"fork":false,"pushed_at":"2025-03-28T20:25:23.000Z","size":257,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T21:27:44.803Z","etag":null,"topics":["go","golang","library","package","queue"],"latest_commit_sha":null,"homepage":"","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/sky93.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":"2025-03-07T13:32:14.000Z","updated_at":"2025-03-28T20:25:12.000Z","dependencies_parsed_at":"2025-03-07T14:40:01.742Z","dependency_job_id":null,"html_url":"https://github.com/sky93/taskflow","commit_stats":null,"previous_names":["sky93/taskflow"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sky93/taskflow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sky93%2Ftaskflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sky93%2Ftaskflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sky93%2Ftaskflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sky93%2Ftaskflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sky93","download_url":"https://codeload.github.com/sky93/taskflow/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sky93%2Ftaskflow/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32256217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T04:23:17.126Z","status":"ssl_error","status_checked_at":"2026-04-25T04:21:53.360Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["go","golang","library","package","queue"],"created_at":"2025-03-11T04:34:23.573Z","updated_at":"2026-04-25T09:02:14.978Z","avatar_url":"https://github.com/sky93.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"logo.png\" alt=\"tracesight\" width=\"200px\"\u003e\n\u003c/div\u003e\n\n# ⏳taskflow\n[![Go Reference](https://pkg.go.dev/badge/github.com/sky93/taskflow.svg)](https://pkg.go.dev/github.com/sky93/taskflow)\n[![Go Report Card](https://goreportcard.com/badge/github.com/sky93/taskflow)](https://goreportcard.com/report/github.com/sky93/taskflow)\n\n**Taskflow** is a lightweight Go library for running background jobs out of a MySQL queue table. It handles:\n\n- Fetching jobs from the database\n- Locking and retrying failed jobs\n- Creating new jobs programmatically\n- Running custom job logic with optional timeouts\n- Structured logging via user-defined callbacks\n- Graceful shutdown of worker pools\n\n---\n\n## Table of Contents\n1. [Installation](#installation)\n2. [Database Schema](#database-schema)\n3. [Quick Start Example](#quick-start-example)\n4. [Contributing](#contributing)\n5. [License](#license)\n\n---\n\n## Installation\n\n```bash\ngo get github.com/sky93/taskflow\n```\n\n---\n\n## Database Schema\n\nYour database should contain a `jobs` table. For example:\n\n```sql\nCREATE TABLE IF NOT EXISTS jobs (\n  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n  operation VARCHAR(50) NOT NULL,\n  status ENUM('PENDING','IN_PROGRESS','COMPLETED','FAILED') NOT NULL DEFAULT 'PENDING',\n  payload JSON NULL,\n  output JSON NULL,\n  error_output JSON NULL,\n  locked_by VARCHAR(50) NULL,\n  locked_until DATETIME NULL,\n  retry_count INT UNSIGNED NOT NULL DEFAULT 0,\n  available_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00',\n  created_at DATETIME NOT NULL,\n  updated_at DATETIME NOT NULL\n);\n```\n\n---\n\n## Quick Start Example\n\nBelow is a **complete**, minimal example showing:\n\n1. Connecting to the database\n2. Creating a `taskflow.Config` and a new `TaskFlow`\n3. Registering a custom job handler\n4. Starting workers\n5. Creating a job\n6. Shutting down gracefully\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"database/sql\"\n    \"fmt\"\n    \"time\"\n\n    _ \"github.com/go-sql-driver/mysql\"\n    \"github.com/sky93/taskflow\"\n)\n\n// MyPayload is the shape of the data we expect in the job payload.\ntype MyPayload struct {\n    Greeting string\n}\n\n// HelloHandler processes jobs of type \"HELLO\".\nfunc HelloHandler(jr taskflow.JobRecord) (any, error) {\n    var payload MyPayload\n    if err := jr.GetPayload(\u0026payload); err != nil {\n        return nil, err\n    }\n\n    // Here we just print the greeting; real logic can be anything.\n    fmt.Println(\"Received greeting:\", payload.Greeting)\n    return nil, nil\n}\n\nfunc main() {\n    ctx := context.Background()\n\n    // 1) Connect to the DB\n    dsn := \"root:password@tcp(127.0.0.1:3306)/myDbName?parseTime=true\"\n    db, err := sql.Open(\"mysql\", dsn)\n    if err != nil {\n        panic(err)\n    }\n    if err := db.Ping(); err != nil {\n        panic(err)\n    }\n    fmt.Println(\"Connected to database.\")\n\n    // 2) Create the taskflow config\n    cfg := taskflow.Config{\n        DB:           db,\n        RetryCount:   3,\n        BackoffTime:  30 * time.Second,\n        PollInterval: 5 * time.Second,\n        JobTimeout:   10 * time.Second,\n\n        // Optional logging\n        InfoLog: func(ev taskflow.LogEvent) {\n            fmt.Printf(\"[INFO] %s\\n\", ev.Message)\n        },\n        ErrorLog: func(ev taskflow.LogEvent) {\n            fmt.Printf(\"[ERROR] %s\\n\", ev.Message)\n        },\n    }\n\n    // 3) Create an instance of TaskFlow\n    flow := taskflow.New(cfg)\n\n    // 4) Register our \"HELLO\" handler\n    flow.RegisterHandler(\"HELLO\", HelloHandler)\n\n    // 5) Start workers (2 concurrent workers)\n    flow.StartWorkers(ctx, 2)\n\n    // Create a new \"HELLO\" job\n    jobID, err := flow.CreateJob(ctx, \"HELLO\", MyPayload{Greeting: \"Hello from TaskFlow!\"}, time.Now())\n    if err != nil {\n        panic(err)\n    }\n    fmt.Printf(\"Created job ID %d\\n\", jobID)\n\n    // Let it run for a few seconds\n    time.Sleep(5 * time.Second)\n\n    // 6) Shutdown gracefully\n    flow.Shutdown(10 * time.Second)\n    fmt.Println(\"All done.\")\n}\n```\n\n---\n\n## Contributing\n\nContributions are welcome! Please follow these steps:\n\n1. **Fork** the repository\n2. Create a new **branch** for your feature or fix\n3. Commit your changes, and **add tests** if possible\n4. Submit a **pull request** and provide a clear description of your changes\n\n---\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsky93%2Ftaskflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsky93%2Ftaskflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsky93%2Ftaskflow/lists"}