Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Cannot import name 'Interval' #70

Open
AdoniasAlcantara opened this issue Apr 4, 2022 · 3 comments
Open

Cannot import name 'Interval' #70

AdoniasAlcantara opened this issue Apr 4, 2022 · 3 comments

Comments

@AdoniasAlcantara
Copy link

when trying to run the example from the README I get the error:

File "/home/adonias/Workspaces/Training/celery_test/proj.py", line 11, in <module>
    from celerybeatmongo.models import PeriodicTask, Interval
ImportError: cannot import name 'Interval' from 'celerybeatmongo.models' (/home/adonias/.local/lib/python3.8/site-packages/celerybeatmongo/models.py)

Any idea why this error?

from celery import Celery

config = {
    "mongodb_scheduler_db": "my_project",
    "mongodb_scheduler_url": "mongodb://localhost:27017",
}

app = Celery('hello', broker='redis://localhost//')
app.conf.update(**config)

from celerybeatmongo.models import PeriodicTask, Interval

periodic = PeriodicTask(
    name='Importing contacts',
    task="proj.import_contacts",
    interval=Interval(every=10, period="seconds") # executes every 10 seconds.
)
periodic.save()
@FurkanSalih
Copy link

FurkanSalih commented Jun 7, 2022

I think README is wrong. Because Interval class is not in models.py but it is in PeriodicTask class. So you can import it with:

from celerybeatmongo.models import PeriodicTask
...
interval=PeriodicTask.Interval(every=10, period="seconds") # executes every 10 seconds.

@AdoniasAlcantara
Copy link
Author

Sorry for the delay and thanks for your reply. I wish someone could update the README to avoid confusion in the future.

@cikay cikay mentioned this issue Nov 15, 2022
@cikay
Copy link
Contributor

cikay commented Nov 15, 2022

Fixed in here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants