Make everything lockable.
Make everything(resource) lockable.
Highly inspired by Jenkins's lockable resources plugin.
And, make it works locally.
Python 3.6+
g lock r s = global lockable resource server
Start your backend firstly:
pip install glockr
# default use port 29410
glockrs start
# or use another port?
# would be better to set it in file (such as ~/.bashrc)
export GLOCKR_PORT=29411 && glockrs start
# and your server will be running on 29411
Or, directly use docker:
docker pull williamfzc/glockr
docker run --rm -p 29410:29410 williamfzc/glockr
Based on FastAPI, All the API of glockr can be easily viewed and executed via http://127.0.0.1:29410/docs.
You can also use it as UI to manage your resource directly.
g lock r c = global lockable resource client
Make sure glockr backend has been started.
glockrc heartbeat
And you will see the help:
➜ glockr git:(master) glockrc
Type: GClient
String form: <glockr.client.GClient object at 0x7f506abcee48>
Usage: glockrc
glockrc acquire-label
glockrc acquire-name
glockrc add
glockrc download
glockrc heartbeat
glockrc release-label
glockrc release-name
glockrc remove
glockrc show-all
glockrc upload
JSON response can be easily handled by other programs.
New a resource object, named "123", label "abc":
in:
glockrc add 123 abc
out:
{"result": True, "reason": ""}
Acquire it by name!
in:
glockrc acquire-name 123
out:
{"result": True, "reason": ""}
After acquirement, resource has been locked!
in:
glockrc acquire-name 123
out:
{"result": False, "reason": "res 123 status: BUSY"}
Label can be used to require locks on multiple resources concurrently.
New a resource object, named "456", label "abc". Then, lock label "abc". By doing this, "123" and "456" (because they have label "abc") will be locked.
in:
glockrc release-name 123
glockrc add 456 abc
glockrc acquire-label abc
glockrc show-all
out:
{"123": {"name": "123", "label": "abc", "status": "BUSY"}, "456": {"name": "456", "label": "abc", "status": "BUSY"}}
Note: glockr server only save your data in python runtime! And once server were stopped, your data will gone and you have to add them again.
But, you can use download
and upload
to sync your data easily.
in:
glockrc download ./data1.json
out:
{"123": {"name": "123", "label": "abc", "status": "BUSY"}, "456": {"name": "456", "label": "abc", "status": "BUSY"}}
Your data will be saved in ./data1.json
. And, you can use them to init your server:
in:
glockrc upload ./data1.json
out:
{"result":true,"reason":""}
{"result":true,"reason":""}
One by one, your data has been uploaded!
Based on C/S, glockr supports different language clients.
Welcome! And please let me know via issue or PR :)