Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tasks wont run always after updating the schedule #221

Open
thisiseddy-ab opened this issue Jul 11, 2022 · 0 comments
Open

Tasks wont run always after updating the schedule #221

thisiseddy-ab opened this issue Jul 11, 2022 · 0 comments

Comments

@thisiseddy-ab
Copy link

thisiseddy-ab commented Jul 11, 2022

Im Testing RedBeat, im creating a task it runs normally but when i update the schedule it stops running,i need to call the function two times to pick up the change and to run.

It is the same for interval tasks to not just cron tasks.

Celery Configuration

broker_url = "redis://localhost:6379/0"
result_backend = "redis://localhost:6379/1"

timezone = "Europe/Vienna"
enable_utc = False

redbeat_redis_url = "redis://localhost:6379/2"

beat_scheduler = 'redbeat.RedBeatScheduler'
beat_max_loop_interval = 5

Creating The Task

def create_crontab_task():
    #local_dt = local_timezone.localize(datetime.now())
    #dt_to_celery = local_dt.astimezone(UTC)
    #nowfun = lambda: dt_to_celery
    
    local_timezone = timezone("Europe/Vienna")
    nowfun = lambda: datetime.now(local_timezone)
    p_task = Entry(
        name= "crontab_task_1",
        task = "task.print_word",
        schedule = crontab(minute="32",hour="13",day_of_month="*",month_of_year="*", day_of_week="*",nowfun=nowfun),
        args=["Crontab Test Task"],
        app = celery
    )
    p_task.save()
    return {"message" : "Cron Task Created"}

Updating The Task

def update_crontab_task():
    try:
        task = Entry.from_key('redbeat:crontab_task_1', app=celery)

        #local_dt = local_timezone.localize(datetime.now())
        #dt_to_celery = local_dt.astimezone(UTC)
        #nowfun = lambda: dt_to_celery

        local_timezone = timezone("Europe/Vienna")
        nowfun = lambda: datetime.now(local_timezone)
        task.schedule = crontab(minute="*/2",hour="*",day_of_month="*",month_of_year="*", day_of_week="*",nowfun=nowfun)

        # We simply change the args passed to the task
        task.args = ["Updatedet Cron Task"]
        task.save()

        return {"message" : "Updatet Sucsesfully"}
    except KeyError:
        return {"message" : "Key Dosent Exsist"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant