Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/enUS/arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Init Policy

There four type init policy for restart RedisBeat,which defined at [redisbeat/constans.py]():

- INIT_POLICY_DEFAULT
- Default policy for RedisBeat, If you miss N times run during your restart, your task will run N times after restart.
- INIT_POLICY_RESET
- Reset all task's last run time to restart time.
- INIT_POLICY_FAST_FORWARD
- If you miss N times run during your restart, your task will only run ONCE after restart and continue from curr time.
- INIT_POLICY_IMMEDIATELY
- Run all task immediately, and reset all task's last run time as curr restart time.
12 changes: 12 additions & 0 deletions docs/zhCN/arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## 初始化策略

RedisBeat 在 [redisbeat/constans.py]() 中定义了 4 种不同的初始化策略,分别为:

- INIT_POLICY_DEFAULT
- RedisBeat 的默认策略,如果在重启期间你错过了 N 次执行,那么重启之后会补足这 N 次执行;
- INIT_POLICY_RESET
- 在重启时将所有任务的开始计数时间重置为当前时间;
- INIT_POLICY_FAST_FORWARD
- 如果在重启期间你错过了 N 次执行,那么重启之后只会执行一次,并且后续将按照正常周期计算;
- INIT_POLICY_IMMEDIATELY
- 在重启后马上执行所有的任务,并且重置计数时间为当前时间;
2 changes: 1 addition & 1 deletion example/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.6-alpine
FROM python:2.7-alpine
WORKDIR /usr/src/app

RUN apk add --no-cache --virtual \
Expand Down
14 changes: 14 additions & 0 deletions example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

.PHONY: worker beat

worker:
celery worker -A tasks -l INFO

beat:
celery beat -A tasks -S redisbeat.RedisScheduler -l DEBUG

add_task:
python add_task.py

rm_task:
python rem_task.py
2 changes: 1 addition & 1 deletion example/add_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
if __name__ == "__main__":
schduler = RedisScheduler(app=app, skip_init=True)
schduler.add(**{
'name': 'sub-perminute',
'name': 'sub-every-3-seconds',
'task': 'tasks.sub',
'schedule': timedelta(seconds=3),
'args': (1, 1)
Expand Down
2 changes: 1 addition & 1 deletion example/rem_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

if __name__ == "__main__":
schduler = RedisScheduler(app=app, skip_init=True)
result = schduler.remove('sub-perminute')
result = schduler.remove('sub-every-3-seconds')
print("rem result: ", result)
5 changes: 2 additions & 3 deletions example/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
if hostname != "beat" and hostname != "worker":
redis_url = 'redis://localhost:6379'


app = Celery('tasks', backend=redis_url, broker=redis_url)

app.conf.update(CELERY_REDIS_SCHEDULER_URL = redis_url)

if hostname == "beat":
if hostname == "devops":
app.conf.update(
CELERYBEAT_SCHEDULE={
'perminute': {
'every-3-seconds': {
'task': 'tasks.add',
'schedule': timedelta(seconds=3),
'args': (1, 1)
Expand Down
13 changes: 10 additions & 3 deletions redisbeat/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
@created at: 2020/3/7
"""

DEFUALT_INIT_POLICY = "DEFAULT"
INIT_POLICY_RESET = "RESET"
INIT_POLICY_DEFAULT = "DEFAULT"
INIT_POLICY_IMMEDIATELY = "IMMEDIATELY"
INIT_POLICY_FAST_FORWARD = "FAST_FORWARD"

INIT_POLICIES = [
INIT_POLICY_RESET,
INIT_POLICY_DEFAULT,
DEFUALT_INIT_POLICY,
INIT_POLICY_IMMEDIATELY,
INIT_POLICY_FAST_FORWARD,
]
]

CONFIG_INIT_POLICY = "CELERY_REDIS_SCHEDULER_INIT_POLICY"
BROKER_URL = "CELERY_REDIS_SCHEDULER_URL"
BROKER_TRANSPORT_OPTIONS = "CELERY_BROKER_TRANSPORT_OPTIONS"
BROKER_KEY = "CELERY_REDIS_SCHEDULER_KEY"
MULTI_NODE_MODE = "CELERY_REDIS_MULTI_NODE_MODE"
LOCK_TTL = "CELERY_REDIS_SCHEDULER_LOCK_TTL"
Loading