Name | m-schedule JSON |
Version |
1.0.1
JSON |
| download |
home_page | https://github.com/mobiovn |
Summary | Tạo schedule chạy theo lịch |
upload_time | 2023-11-24 03:19:42 |
maintainer | |
docs_url | None |
author | MOBIO |
requires_python | |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# <h2 id="title"> Thư viện Schedule trên ngôn ngữ Python để chạy service background.</h2>
# Copyright: MobioVN
# CHANGE LOG:
## v1.0.1
- Support Redis cluster
## v1.0.0
- Breaking change:
+ Core concept của phiên bản này là các schedule có thể chạy song song nhằm giải quyết các bài toán như xử lý import excel, csv đồng thời.
+ Để tránh N schedule cùng xử lý 1 file, call self.check_job_allow_running(str_job_id) để check xem job đấy trong 5seconds vừa qua đã có được worker nào xử lý hay không?
+ Giải thuật ở đây là tận dụng Atomic của redis, sử dụng incrby function để check redis-key đã tồn tại chưa? chỉ có worker thao tác incrby đầu tiên(return value = 1) mới có quyền xử lý file
## v0.6.7
- Sửa lỗi key "last_run"
#### Cài đặt:
`$ pip3 install m-schedule`
#### Sử dụng:
1. Tạo class thực thi scheduler kế thừa từ class BaseScheduler
```python
class TestScheduler(BaseScheduler):
def owner_do(self):
lst_job = db.excel_file.find({"status":0}).limit(1)
for job in lst_job:
if self.check_job_allow_running(str(job.id)):
print("execute {}".format(job.id))
else:
print("job {} is running".format(job.id))
pass
def get_schedule(self):
"""
hàm xác định thời điểm chạy của scheduler, bằng cách xử dụng thư viện schedule
Các ví dụ hướng dẫn cách xác định thời gian chạy
1. scheduler chỉ thực hiện công việc một lần duy nhất.
return None
2. scheduler sẽ thực hiện mỗi 10 phút một lần.
return schedule.every(10).minutes
3. scheduler sẽ thực hiện hàng ngày vào lúc 10h 30 phút.
return schedule.every().day.at("10:30")
4. scheduler sẽ thực hiện sau mỗi giờ.
return schedule.every().hour
5. scheduler sẽ thực hiện vào mỗi thứ 2 hàng tuần.
return schedule.every().monday
6. scheduler sẽ thực hiện vào mỗi thứ 5 hàng tuần và vào lúc 13h 15'.
return schedule.every().wednesday.at("13:15")
"""
return schedule.every(10).minutes
```
2. Đăng ký scheduler với factory
```python
factory = SchedulerFactory()
factory.add(TestScheduler(name="MyScheduler", redis_uri="redis://redis-server:6379/0"))
# sample using redis cluster
factory.add(TestScheduler(name="MyScheduler1", redis_cluster_uri="redis://redis-cluster.redis.svc.cluster.local:6379/0", redis_type=RedisType.REPLICA))
factory.run()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/mobiovn",
"name": "m-schedule",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "MOBIO",
"author_email": "contact@mobio.vn",
"download_url": "https://files.pythonhosted.org/packages/f1/94/54aa7b2675ad8bb2d00337a6d14a98a14faa32872568d12f49cfe1f169ac/m-schedule-1.0.1.tar.gz",
"platform": null,
"description": "# <h2 id=\"title\"> Th\u01b0 vi\u1ec7n Schedule tr\u00ean ng\u00f4n ng\u1eef Python \u0111\u1ec3 ch\u1ea1y service background.</h2>\n\n# Copyright: MobioVN\n\n# CHANGE LOG:\n## v1.0.1\n- Support Redis cluster\n\n## v1.0.0\n- Breaking change:\n + Core concept c\u1ee7a phi\u00ean b\u1ea3n n\u00e0y l\u00e0 c\u00e1c schedule c\u00f3 th\u1ec3 ch\u1ea1y song song nh\u1eb1m gi\u1ea3i quy\u1ebft c\u00e1c b\u00e0i to\u00e1n nh\u01b0 x\u1eed l\u00fd import excel, csv \u0111\u1ed3ng th\u1eddi.\n + \u0110\u1ec3 tr\u00e1nh N schedule c\u00f9ng x\u1eed l\u00fd 1 file, call self.check_job_allow_running(str_job_id) \u0111\u1ec3 check xem job \u0111\u1ea5y trong 5seconds v\u1eeba qua \u0111\u00e3 c\u00f3 \u0111\u01b0\u1ee3c worker n\u00e0o x\u1eed l\u00fd hay kh\u00f4ng?\n + Gi\u1ea3i thu\u1eadt \u1edf \u0111\u00e2y l\u00e0 t\u1eadn d\u1ee5ng Atomic c\u1ee7a redis, s\u1eed d\u1ee5ng incrby function \u0111\u1ec3 check redis-key \u0111\u00e3 t\u1ed3n t\u1ea1i ch\u01b0a? ch\u1ec9 c\u00f3 worker thao t\u00e1c incrby \u0111\u1ea7u ti\u00ean(return value = 1) m\u1edbi c\u00f3 quy\u1ec1n x\u1eed l\u00fd file\n \n## v0.6.7\n- S\u1eeda l\u1ed7i key \"last_run\"\n\n\n#### C\u00e0i \u0111\u1eb7t:\n`$ pip3 install m-schedule`\n\n#### S\u1eed d\u1ee5ng:\n\n1. T\u1ea1o class th\u1ef1c thi scheduler k\u1ebf th\u1eeba t\u1eeb class BaseScheduler\n ```python\n class TestScheduler(BaseScheduler):\n def owner_do(self):\n lst_job = db.excel_file.find({\"status\":0}).limit(1)\n for job in lst_job:\n if self.check_job_allow_running(str(job.id)):\n print(\"execute {}\".format(job.id))\n else:\n print(\"job {} is running\".format(job.id))\n pass\n \n def get_schedule(self):\n \"\"\"\n h\u00e0m x\u00e1c \u0111\u1ecbnh th\u1eddi \u0111i\u1ec3m ch\u1ea1y c\u1ee7a scheduler, b\u1eb1ng c\u00e1ch x\u1eed d\u1ee5ng th\u01b0 vi\u1ec7n schedule\n C\u00e1c v\u00ed d\u1ee5 h\u01b0\u1edbng d\u1eabn c\u00e1ch x\u00e1c \u0111\u1ecbnh th\u1eddi gian ch\u1ea1y\n 1. scheduler ch\u1ec9 th\u1ef1c hi\u1ec7n c\u00f4ng vi\u1ec7c m\u1ed9t l\u1ea7n duy nh\u1ea5t.\n return None\n 2. scheduler s\u1ebd th\u1ef1c hi\u1ec7n m\u1ed7i 10 ph\u00fat m\u1ed9t l\u1ea7n.\n return schedule.every(10).minutes\n 3. scheduler s\u1ebd th\u1ef1c hi\u1ec7n h\u00e0ng ng\u00e0y v\u00e0o l\u00fac 10h 30 ph\u00fat.\n return schedule.every().day.at(\"10:30\")\n 4. scheduler s\u1ebd th\u1ef1c hi\u1ec7n sau m\u1ed7i gi\u1edd.\n return schedule.every().hour\n 5. scheduler s\u1ebd th\u1ef1c hi\u1ec7n v\u00e0o m\u1ed7i th\u1ee9 2 h\u00e0ng tu\u1ea7n.\n return schedule.every().monday\n 6. scheduler s\u1ebd th\u1ef1c hi\u1ec7n v\u00e0o m\u1ed7i th\u1ee9 5 h\u00e0ng tu\u1ea7n v\u00e0 v\u00e0o l\u00fac 13h 15'.\n return schedule.every().wednesday.at(\"13:15\")\n \"\"\"\n return schedule.every(10).minutes\n ```\n\n2. \u0110\u0103ng k\u00fd scheduler v\u1edbi factory\n ```python\n factory = SchedulerFactory()\n factory.add(TestScheduler(name=\"MyScheduler\", redis_uri=\"redis://redis-server:6379/0\"))\n # sample using redis cluster\n factory.add(TestScheduler(name=\"MyScheduler1\", redis_cluster_uri=\"redis://redis-cluster.redis.svc.cluster.local:6379/0\", redis_type=RedisType.REPLICA))\n factory.run()\n ```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "T\u1ea1o schedule ch\u1ea1y theo l\u1ecbch",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/mobiovn"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "261acf560f437745df94172d6965ec94a3b8ea5fc3db72a5be14090705aad2ca",
"md5": "2261d9c6f85188539c4f986eb9084381",
"sha256": "19ad7d1d5f8f6f0919102b47ef6cfb8a806ba9ff856a64d7b93f911029e08c34"
},
"downloads": -1,
"filename": "m_schedule-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2261d9c6f85188539c4f986eb9084381",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4388,
"upload_time": "2023-11-24T03:19:41",
"upload_time_iso_8601": "2023-11-24T03:19:41.327103Z",
"url": "https://files.pythonhosted.org/packages/26/1a/cf560f437745df94172d6965ec94a3b8ea5fc3db72a5be14090705aad2ca/m_schedule-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f19454aa7b2675ad8bb2d00337a6d14a98a14faa32872568d12f49cfe1f169ac",
"md5": "32c4869551c20812d155444209f80d70",
"sha256": "e1b4f51beaa428fc109baa932684196e576a56ca5d63a639463d55798c452396"
},
"downloads": -1,
"filename": "m-schedule-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "32c4869551c20812d155444209f80d70",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3784,
"upload_time": "2023-11-24T03:19:42",
"upload_time_iso_8601": "2023-11-24T03:19:42.633104Z",
"url": "https://files.pythonhosted.org/packages/f1/94/54aa7b2675ad8bb2d00337a6d14a98a14faa32872568d12f49cfe1f169ac/m-schedule-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-24 03:19:42",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "m-schedule"
}