{"id":18896603,"url":"https://github.com/cguz/task-management-service","last_synced_at":"2026-02-28T13:30:21.611Z","repository":{"id":52012475,"uuid":"365197768","full_name":"cguz/task-management-service","owner":"cguz","description":"Handle the execution of multiple types of Tasks.","archived":false,"fork":false,"pushed_at":"2021-05-11T07:39:47.000Z","size":709,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-31T08:14:47.851Z","etag":null,"topics":["execution","queue","sequence","tasks"],"latest_commit_sha":null,"homepage":"","language":"C++","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/cguz.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}},"created_at":"2021-05-07T10:29:36.000Z","updated_at":"2024-04-01T08:56:16.000Z","dependencies_parsed_at":"2022-08-26T13:25:51.520Z","dependency_job_id":null,"html_url":"https://github.com/cguz/task-management-service","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cguz%2Ftask-management-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cguz%2Ftask-management-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cguz%2Ftask-management-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cguz%2Ftask-management-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cguz","download_url":"https://codeload.github.com/cguz/task-management-service/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239876747,"owners_count":19711947,"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":["execution","queue","sequence","tasks"],"created_at":"2024-11-08T08:34:42.698Z","updated_at":"2026-02-28T13:30:21.493Z","avatar_url":"https://github.com/cguz.png","language":"C++","readme":"[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://gitHub.com/cguz/)\n[![Eclipse](https://img.shields.io/badge/-Eclipse%20C%2FC%2B%2B-blueviolet)](https://eclipse.org/) \n[![Eclipse](https://img.shields.io/badge/-Cmake-success)](https://cmake.org/) \n[![Drawio](https://img.shields.io/badge/-Drawio-orange)](https://drawio-app.com/)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/79bf6932c2e844eea15d0fb1ed7e415c)](https://app.codacy.com/gh/cguz/task-management-service)\n\n# Task Management Service\n\n\u003ccenter\u003e\u003ca href=\"http://visionspace.com/\"\u003e\u003cimg src=\"https://user-images.githubusercontent.com/15159632/117484138-f7920900-af66-11eb-8def-6e9880860c4a.png\" alt=\"VisionSpace\" title=\"VisionSpace\" height=\"100px\" /\u003e\u003c/a\u003e\u003c/center\u003e\n\nAuthor: Cesar Augusto Guzman Alvarez [@cguz](https://github.com/cguz/)\n\n[**Documentation**](https://task-management-service.readthedocs.io/en/latest/)\n\n## Description\n\nThe goal of this service is to handle the execution of multiple types of Tasks. \n\n### Requirements\n\n*   A Task can be executed instantly or can be scheduled for later execution;\n*   A Task can be in one of the following states: QUEUED, RUNNING, SUCCESS, FAILED;\n*   Failed Tasks shall not have any side effects;\n*   A user can cancel Tasks using the Task Management Service.\n\n### Examples of the Tasks to execute\n\n*   Batch data load to a data warehouse;\n*   Index files;\n*   Send notifications.\n\n## Solution\n\nThe proposed solution not only meets the requirements but also implements the following new functionalities:\n\n*   Execute a task and/or a set of tasks.\n*   Execute a task instantly or scheduled for later execution if more tasks are executing.\n*   Implementation with thread to execute the tasks form the client side.\n*   Prepare before execution the task or set of tasks to execute.\n*   Simulate randomly the duration of a task. The duration can be a value between 0 and 5.\n*   Simulate randomly the failure of a task. The task can fail with a probability of 0.05. \n*   Separate the task generation from the task execution. Allowing to add more tasks and monitor their execution easily.\n*   Add two more states, CANCEL, and PAUSE (explained later).\n*   Implement integration test. The Unit test can be implemented similarl way.\n\n### Design\n\nThe design is in the folder ( 📁 ) [\"design\"](https://github.com/cguz/task-management-service/tree/main/design)\n\nThe class diagram is as follow:\n\n\u003cimg src=\"https://raw.githubusercontent.com/cguz/task-management-service/4fb73a3c4c544c2f0ba223eb7c79e6f2c941b626/design/TaskManagementService.svg\" alt=\"Architecture\" title=\"Architecture\" height=\"600px\" /\u003e\n\nThe **ClientControl** class creates tasks sequence and executes one task or a set of tasks (tasks sequence).\n\nThe **ClientControl** generates the tasks sequence through the class  **SequenceTasksCatalogConstructor**, procedure build(id: short), where id is the identifier of the tasks sequence. \n\nThe **SequenceTasksCatalogConstructor** class contains a catalog of task sequence factories. A tasks sequence factory (class **SequenceTasksFactory**) contains the necessary information to create one (class **Task**) or more tasks (class **SequenceTasks**) to be executed.\n\nThe **TaskManagementService** class is the start point to execute any task or task sequence.\n\nWe implemented the **SequenceTasks** (tasks sequence), **Task**, and **ITask** classes using the composite pattern. This pattern allows us to treat the **SequenceTasks** and **Task** classes as a single instance of the same **ITask** class. \n\nThe **SequenceTasks** class controls the iteration of the tasks throughout the private variable **iterate**, which is an instance of the **ControllIterator** class. The **ControllIterator** class allows easy tracking of the current and previous tasks executed. The **SequenceTasks** class works like a queue.\n\nThe **TaskSendNotifications**, **TaskIndexFiles**, and **TaskBatchDataLoad** classes inherit from the class **Task** and implement Examples of the Tasks to execute Batch data load to a data warehouse; Index files; and Send notifications, respectively.\n\nFinally, we applied a finite state machine (using the state design pattern) to control the execution state of the tasks. The state variable in the **ITask** class contains the current state. \n\nThe state transition of a task's finite state machine is as follow:\n\n\u003cimg src=\"https://raw.githubusercontent.com/cguz/task-management-service/b4911a248339fdd3fadec891f4efc77b691dc474/design/StateDiagram.svg\" alt=\"State transition diagram\" title=\"State transition diagram\" height=\"400px\" /\u003e\n\nThe states are:\n\n*   QUEUED : means that the tasks are planned for their execution.\n*   RUNNING : means that the tasks are executing.\n*   SUCCESS : means that the tasks finish successfully.\n*   FAILED : means that the task fails during its execution.\n\nWe added two more states:\n\n*   CANCEL : means that the user cancels the task.\n*   PAUSED : means that the task is stopped and can be resumed. \n  \n## Development\nThe source code in C++ is in the folder ( 📁 ) [\"src/cplusplus/\"](https://github.com/cguz/task-management-service/tree/main/src/cplusplus). In that folder, we can find all the computational requirements needed to execute the code.\n\nSince the repository contains submodules (google test library), please, clone the repository as follow:\n\n    git clone --recurse-submodules -j8 https://github.com/cguz/task-management-service.git\n\nSome examples of how to use the **ClientControl** class are in the files:\n\n*   \"src/cplusplus/src/main.cpp\"\n*   \"src/cplusplus/tests/Integration-Test.cpp\"\n\nFor instance, the method **testExecutionOneTask**:\n\n    void testExecutionOneTask() {\n\n      createClientControl();\n\n      cout \u003c\u003c \"\\n\\n------------------------------------------\" \u003c\u003c endl;\n      cout \u003c\u003c \"3. Choose the sequence task SEQ_TASKS_GROUP1 for execution\" \u003c\u003c endl;\n      cout \u003c\u003c \"--------------------------------------------\" \u003c\u003c endl;\n\n      controlClient-\u003eselect(SequenceTasksCatalogConstructor::SEQ_TASKS_GROUP1);\n\n      try {\n\n        cout \u003c\u003c \"\\n\\n--------------------------------------------\";\n        cout \u003c\u003c \"\\n4. START The execution of SEQ_TASKS_GROUP1 \";\n        cout \u003c\u003c \"\\n--------------------------------------------\" \u003c\u003c endl;\n\n        controlClient-\u003eexecute();\n\n        cout \u003c\u003c \"\\n\\n-----------------------------------------\";\n        cout \u003c\u003c \"\\n4. END The execution of SEQ_TASKS_GROUP1\";\n        cout \u003c\u003c \"\\n-----------------------------------------\" \u003c\u003c endl;\n\n      } catch(char const* exception) {\n        cout \u003c\u003c endl \u003c\u003c exception \u003c\u003c endl;\n      }\n    }\n    \nSelect the tasks sequence **SEQ_TASKS_GROUP1** that contains only one dummy Task (see the factory file [TasksGroup1Factory.cpp](https://github.com/cguz/task-management-service/blob/main/src/cplusplus/src/TasksManagementService/Creational/Factories/TasksGroup1Factory.cpp)). Then, execute the task.\n\nAnothe example is the method **testClientTasksAddNewOnePause**:\n\n    void testClientTasksAddNewOnePause() {\n\n      createClientControlCustomCatalog();\n\n      cout \u003c\u003c \"\\n\\n-----------------------------------\" \u003c\u003c endl;\n      cout \u003c\u003c \"3. Choose the sequence task SEQ_CUSTOM1 for execution\" \u003c\u003c endl;\n      cout \u003c\u003c \"---------------------------------------\" \u003c\u003c endl;\n\n      // SEQ_CUSTOM1 contains three tasks: 1.) Batch data load to a data warehouse;, 2) Index files; and 3) Send notifications.\n      controlClient-\u003eselect(CustomSequenceTasksCatalogConstructor::SEQ_CUSTOM1);\n\n      try {\n\n        cout \u003c\u003c \"\\n\\n--------------------------------------------\";\n        cout \u003c\u003c \"\\n4. START The execution of SEQ_CUSTOM1 \";\n        cout \u003c\u003c \"\\n--------------------------------------------\" \u003c\u003c endl;\n\n        // execute the tasks in parallel\n        std::thread executeThread(\u0026ClientControl::execute, std::ref(controlClient));\n        executeThread.detach();\n\n        // add the new task\n        controlClient-\u003eadd(new TaskIndexFile());\n\n        // wait two seconds\n        cout \u003c\u003c endl \u003c\u003c\"wait for 2 seconds \"\u003c\u003cendl;\n        std::this_thread::sleep_for(std::chrono::seconds(2));\n\n        // pause the execution of the tasks.\n        controlClient-\u003epause();\n\n        // wait five seconds\n        cout \u003c\u003c \"wait for 5 seconds \"\u003c\u003cendl;\n        std::this_thread::sleep_for(std::chrono::seconds(5));\n\n        controlClient-\u003eexecute();\n\n        // wait until the tasks finish their execution\n        std::this_thread::sleep_for(std::chrono::seconds(30));\n\n        cout \u003c\u003c \"\\n\\n-----------------------------------------\";\n        cout \u003c\u003c \"\\n4. END The execution of SEQ_CUSTOM1\";\n        cout \u003c\u003c \"\\n-----------------------------------------\" \u003c\u003c endl;\n\n      } catch(char const* exception) {\n        cout \u003c\u003c endl \u003c\u003c exception \u003c\u003c endl;\n      }\n    }\n    \nThis method selects the tasks sequence **SEQ_TASKS_GROUP1** that contains three tasks: 1.) Batch data load to a data warehouse;, 2) Index files; and 3) Send notifications (see the factory file [CustomSeqExampleTasksToExecuteFactory.cpp](https://github.com/cguz/task-management-service/blob/main/src/cplusplus/src/TasksManagementService/CLIENT/Creational/Factories/CustomSeqExampleTasksToExecuteFactory.cpp)). \n\nThen, execute the task sequence using the std::thread. During execution add a new Task Index File, and wait for two seconds. Next, it pauses the task sequence for 5 seconds and executes it again. Finally, it waits for 30 seconds until the tasks sequence thread finishes.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcguz%2Ftask-management-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcguz%2Ftask-management-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcguz%2Ftask-management-service/lists"}