{"id":16132927,"url":"https://github.com/icpd/weightask","last_synced_at":"2025-03-18T15:30:46.415Z","repository":{"id":187820602,"uuid":"677035563","full_name":"icpd/weightask","owner":"icpd","description":"Tasks with weights","archived":false,"fork":false,"pushed_at":"2023-12-16T15:48:44.000Z","size":28,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-10T22:35:14.694Z","etag":null,"topics":[],"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/icpd.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-08-10T15:29:49.000Z","updated_at":"2024-03-11T09:33:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"bd1b494e-5e08-435d-bbe5-479814e746b0","html_url":"https://github.com/icpd/weightask","commit_stats":null,"previous_names":["icpd/priortask"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icpd%2Fweightask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icpd%2Fweightask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icpd%2Fweightask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icpd%2Fweightask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icpd","download_url":"https://codeload.github.com/icpd/weightask/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221713427,"owners_count":16868256,"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-10-09T22:35:16.356Z","updated_at":"2024-10-27T17:53:14.205Z","avatar_url":"https://github.com/icpd.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Weight Task\n## Introduction\nThis Go-based project provides a system for managing and executing tasks based on their weight. Specifically, it concurrently executes a collection of tasks and returns the result of the one with the highest weight.\n## How It Works\nIn the context of the Weight Task Processor, a \"Task\" is defined as any operation with a defined Weight and an Execute function. Here's what these mean:\n- **Weight**: An integer indicating relative importance. Higher numbers indicate higher weight.  \n- **PerformTask**: The function that performs the given task.    \n\nTask processing involves two major steps:  \n1. **Adding Tasks**: Tasks to be executed are added into the Weight Task Processor using the AddTask method. Each task is an instance of a struct that implements the Task interface.\n2. **Processing Tasks**: The ProcessTasks function executes all tasks concurrently and retrieves the result from the task with the highest weight. If multiple tasks share the same highest weight, it will return the first result.  \n## How to Use\nHere's a basic example of how to use the Weight Task Processor:  \n1. Implement the Task interface in your task struct.\n2. Initiate a new instance of NewTaskController via NewTaskController().\n3. Add tasks into the Tasker via AddTask.\n4. Call the ProcessTasks method to begin executing tasks. This will return the result of the highest weight task that is valid. If no tasks are valid, it will return an error.\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/icpd/weightask\"\n)\n\ntype MyTask struct {\n\tweight int\n\tv      string\n}\n\nfunc (t MyTask) Weight() int {\n\treturn t.weight\n}\n\nfunc (t MyTask) PerformTask() (any, error) {\n\ttime.Sleep(time.Second * time.Duration(t.weight))\n\treturn t.v, nil\n}\n\nfunc main() {\n\ttc := weightask.NewTaskController()\n\n\t// add tasks\n\ttc.AddTask(\u0026MyTask{weight: 1, v: \"task 1\"})\n\ttc.AddTask(\u0026MyTask{weight: 2, v: \"task 2\"})\n\ttc.AddTask(\u0026MyTask{weight: 3, v: \"task 3\"})\n\n\t// process tasks\n\tres, err := tc.ProcessTasks(context.Background())\n\tif err != nil {\n\t\tfmt.Println(\"Error:\", err)\n\t\treturn\n\t}\n\n\tfmt.Println(\"Result:\", res) // Result: task 3\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficpd%2Fweightask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficpd%2Fweightask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficpd%2Fweightask/lists"}