{"id":19328080,"url":"https://github.com/inab/bgserver","last_synced_at":"2025-09-09T05:45:56.033Z","repository":{"id":136287879,"uuid":"240923220","full_name":"inab/BGServer","owner":"inab","description":"Python library which helps creating deattached, background servers for web services which need to do some heavy lifting work","archived":false,"fork":false,"pushed_at":"2021-10-02T00:32:57.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-01-06T07:26:07.800Z","etag":null,"topics":["library","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inab.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":"2020-02-16T16:19:53.000Z","updated_at":"2021-10-05T12:54:10.000Z","dependencies_parsed_at":"2023-04-09T03:33:29.309Z","dependency_job_id":null,"html_url":"https://github.com/inab/BGServer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inab%2FBGServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inab%2FBGServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inab%2FBGServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inab%2FBGServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inab","download_url":"https://codeload.github.com/inab/BGServer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240429146,"owners_count":19799804,"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":["library","python"],"created_at":"2024-11-10T02:20:08.707Z","updated_at":"2025-02-24T06:28:22.646Z","avatar_url":"https://github.com/inab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Heavy-lifting background server library\n\nThis library has been designed to delegate long, heavy-lifting background jobs into a server. The server is created on demand, and the program using it communicates with the server using a UNIX socket. The communication protocol on both ways is:\n\n| Byte | Var | Dword | Var |\n| --- | --- | --- | --- |\n| `Label` length | `Label` | `Payload` length | `Payload` |\n\nThe messages follow next rules:\n\n* `Label` length is 1 byte, so labels cannot be longer than 255.\n\n* `Label` is, by default UTF-8 encoded.\n\n* When there is no label, the label length must be 0.\n\n* `Payload` length is an unsigned integer, using 4 bytes in big endian.\n\n* `Payload` is, by default UTF-8 encoded JSON, so clients in other programming languages can encode/decode it.\n\n* When there is no payload, the payload length must be 0.\n\n## Library usage\n\n```python\nclass TestStreamRequestHandler(BGRequestHandler):\n\tdef handleRequest(self,label,payload):\n\t\twith open(\"/tmp/testlog.txt\",mode=\"a\",encoding=\"utf-8\") as l:\n\t\t\tl.write(str(time.time())+\"\\n\")\n\t\t\timport json\n\t\t\tjson.dump(self.server.config,l)\n\t\t\n\t\t# And sending the example\n\t\treturn \"ECHO\",{\"label\": label, \"payload\": payload}\n\n\nsetupBlock = {\n\t\"server\": {\n\t\t\"lock\": \"/tmp/bgserver.lock\",\n\t\t\"socket\": \"/tmp/bgserver.socket\",\n\t}\n}\n\n# Create the instance which will help\nbgServer = BGServer(setupBlock,handlerClass=TestStreamRequestHandler)\n```\n\nThe initialization accepts a dictionary, where the keys `.server.lock` and `server.socket` are honoured when\nthe used lock file and UNIX socket are created. Therefore, their paths must be in an existing, writable directory.\n\n```python\nrLabel , rPayload = bgServer.talkServer(\"A Label\",{\"payload\": ...})\n```\n\nEach time a client wants to send a message to the background server, the `talkServer` method is used. It returns the\nlabel and the payload sent by the server. If there is no background server just running (or it died) for the heavy\nlifting tasks, it is created.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finab%2Fbgserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finab%2Fbgserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finab%2Fbgserver/lists"}