{"id":19024675,"url":"https://github.com/yukihirop/eg_foreman","last_synced_at":"2025-07-16T01:46:28.639Z","repository":{"id":56166357,"uuid":"313054321","full_name":"yukihirop/eg_foreman","owner":"yukihirop","description":"Example in rust of the core part of foreman","archived":false,"fork":false,"pushed_at":"2020-11-23T08:02:27.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-02T01:43:02.154Z","etag":null,"topics":["example","foreman","io","multiprocess","multithread","pipe","rust","signals"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/yukihirop.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":"2020-11-15T14:53:39.000Z","updated_at":"2020-11-23T07:57:16.000Z","dependencies_parsed_at":"2022-08-15T14:00:24.459Z","dependency_job_id":null,"html_url":"https://github.com/yukihirop/eg_foreman","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihirop%2Feg_foreman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihirop%2Feg_foreman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihirop%2Feg_foreman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihirop%2Feg_foreman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yukihirop","download_url":"https://codeload.github.com/yukihirop/eg_foreman/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240072132,"owners_count":19743526,"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":["example","foreman","io","multiprocess","multithread","pipe","rust","signals"],"created_at":"2024-11-08T20:37:59.672Z","updated_at":"2025-02-21T19:12:18.651Z","avatar_url":"https://github.com/yukihirop.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Example in rust of the core part of foreman\n\nIt is an implementation example in rust of IO processing and signal processing in multithread as done by [foreman](https://github.com/ddollar/foreman) of ruby.  \n\n- IO process in multi thread\n- handle signlas in another thread\n- child wait in another thread\n\nSince it is a sample, unlike `foreman`, it does not have the flexibility to define a process in `Procfile`.  \nThe processes that can be executed are as follows.  \n\n|process|concurrency|command|\n|---|-----------|-------|\n|exit_0|1| `sleep 5 \u0026\u0026 echo 'success' \u0026\u0026 exit 0;`|\n|exit_1|1| `sleep 5 \u0026\u0026 echo 'failed' \u0026\u0026 exit 1;`|\n|loop|2|`while :; do sleep 1 \u0026\u0026 echo 'hello world'; done;`|\n\n\nThe behavior is that when exit_0 or exit_1 exits after 5 seconds, the remaining child processes will be signaled with a `SIGTERM` and killed.\n\n![image](https://user-images.githubusercontent.com/11146767/99929079-1f156080-2d8f-11eb-8315-ae7588d21d31.png)\n\n\u003cdetails\u003e\n\n```\n$ cargo run\n    Finished dev [unoptimized + debuginfo] target(s) in 0.08s\n     Running `target/debug/eg_foreman`\nsystem    | exit_0.1  start at pid: 11350\nsystem    | loop.1    start at pid: 11351\nsystem    | exit_1.1  start at pid: 11352\nsystem    | loop.2    start at pid: 11353\nloop.2    | hello world\nloop.1    | hello world\nloop.1    | hello world\nloop.2    | hello world\nloop.2    | hello world\nloop.1    | hello world\nloop.1    | hello world\nloop.2    | hello world\nexit_1.1  | failed\nexit_0.1  | success\nsystem    | sending SIGTERM for loop.1    at pid 11351\nsystem    | sending SIGTERM for exit_1.1  at pid 11352\nsystem    | sending SIGTERM for loop.2    at pid 11353\nsystem    | exit 0\n```\n\n\u003c/details\u003e\n\nIf \u003ckbd\u003ectrl-c\u003c/kbd\u003e is detected within 5 seconds, `SIGTERM` will be sent to all child processes and the process will be killed.\n\n![image](https://user-images.githubusercontent.com/11146767/99907366-c9ee3600-2d1f-11eb-809f-7ab562ee3698.png)\n\n\u003cdetails\u003e\n\n```\n$ cargo run\n    Finished dev [unoptimized + debuginfo] target(s) in 0.09s\n     Running `target/debug/eg_foreman`\nsystem    | exit_0.1  start at pid: 43204\nsystem    | loop.1    start at pid: 43205\nsystem    | exit_1.1  start at pid: 43206\nsystem    | loop.2    start at pid: 43207\nloop.2    | hello world\nloop.1    | hello world\nloop.1    | hello world\nloop.2    | hello world\n^Csystem  | ctrl-c detected\nsystem    | sending SIGTERM for children\nsystem    | sending SIGTERM for exit_0.1  at pid 43204\nsystem    | sending SIGTERM for loop.1    at pid 43205\nsystem    | sending SIGTERM for exit_1.1  at pid 43206\nsystem    | sending SIGTERM for loop.2    at pid 43207\nsystem    | exit 0\n```\n\n\u003c/details\u003e\n\nIf you generalize this, you can make a foreman. You did it. 🎉\n\n## Development\n\nExecutte Test\n\n```bash\ncargo test\n# or\ncargo test -- --nocapture\n```\n\n\n## Environment\n\n|name|desc|defaul|\n|----|----|------|\n|COLOR|Color the output|true|\n\n## Reference\n\nI really referred to the implementation of the following repository.\n\n- [fors](https://github.com/jtdowney/fors)\n- [arpx](https://github.com/jaredgorski/arpx)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyukihirop%2Feg_foreman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyukihirop%2Feg_foreman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyukihirop%2Feg_foreman/lists"}