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

please document required setup for scheduling tasks from python code #53

Open
hamr opened this issue Aug 16, 2022 · 2 comments
Open

please document required setup for scheduling tasks from python code #53

hamr opened this issue Aug 16, 2022 · 2 comments

Comments

@hamr
Copy link

hamr commented Aug 16, 2022

The documentation helpfully provides examples of how to instantiate a Scheduler and run tasks, e.g.

scheduler = Scheduler()
result = scheduler.run(main())

However, that does not appear to take advantage of caching -- tasks run every time -- so it's not quite analogous with running something like

client = RedunClient()
client.execute(["redun", "run", "tasks.py", "main"])

I'm guessing that's because scheduler object isn't making use of the database. And I expect it's relevant that I'm seeing this message when calling scheduler.run().

INFO     redun:__init__.py:1199 Upgrading db from version -1.0 to 3.1...

How do you set up a scheduler object so that it behaves more like calling redun on the command line? Or do you recommend using RedunClient instead? And could you please add that to the docs?

@mattrasmus
Copy link
Collaborator

mattrasmus commented Aug 17, 2022

Hi @hamr thanks for posting this question. It does appear we haven't fully documented this case. We'll add that. In the meantime here is how you configure the Scheduler to use a persistent database (e.g. sqlite). By default, Scheduler() will use an in-memory database that will not persist the cache between executions (which is what you are seeing).

from redun import Scheduler
from redun.config import Config

scheduler = Scheduler(config=Config({
    "backend": {
        "db_uri": "sqlite:///redun.db",
    }
}))
scheduler.load()  # Auto-creates the redun.db file as needed and starts a db connection.
result = scheduler.run(main())

In our own code, where we embed a redun Scheduler inside a larger python application we instantiate Scheduler like above. RedunClient() is really only used in tests.

Let me know if that helps.

@hamr
Copy link
Author

hamr commented Aug 18, 2022

Excellent, thank you!

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

No branches or pull requests

2 participants