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

BUG set_repo doesn't work, though it is mentioned in the documentation #108

Open
vamshiaruru-virgodesigns opened this issue Sep 22, 2022 · 4 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@vamshiaruru-virgodesigns

Describe the bug
I was going through the documentation here: https://rocketry.readthedocs.io/en/stable/cookbook/robust_applications.html?highlight=email#to-csv , and following the steps to add a repo to an app session, I get the error:

AttributeError: 'Session' object has no attribute 'set_repo'

To Reproduce
This simple scripts will produce the error:

from rocketry import Rocketry
from rocketry.log import LogRecord
from redbird.repos import CSVFileRepo

app = Rocketry(config={
    'task_execution': 'async',
    'silence_task_prerun': True,
    'silence_task_logging': True,
    'silence_cond_check': True
})
repo = CSVFileRepo(model=LogRecord, filename="tasks.csv")
repo.create()
app.session.set_repo(repo, delete_existing=True)

Expected behavior
The repo is set without any errors

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOs
  • Python version: Python 3.9.13

Additional context
What else can I do to set the repo in the meantime?

@vamshiaruru-virgodesigns vamshiaruru-virgodesigns added the bug Something isn't working label Sep 22, 2022
@Miksus
Copy link
Owner

Miksus commented Sep 22, 2022

Thanks for reporting this! Indeed, it seems the method was forgotten to be implemented. Cannot remember what I though when I wrote that piece of docs.

Rocketry simply extends the logging library and basically you just need a redbird.logging.RepoHandler in the logger called rocketry.task:

import logging
from redbird.repos import CSVFileRepo
from rocketry.log import LogRecord

from redbird.logging import RepoHandler

repo = CSVFileRepo(model=LogRecord, filename="tasks.csv")
repo.create()

task_logger = logging.getLogger("rocketry.task")
task_logger.handlers.insert(0, RepoHandler(repo=repo))

Put this somewhere before starting the app. Note that I used insert to make sure this is the first RepoHandler as the first repo handler is used for read and write from task logs. You can add other handlers as well as you wish.

I'll revisit this on the weekend.

@vamshiaruru-virgodesigns
Copy link
Author

vamshiaruru-virgodesigns commented Sep 22, 2022

Thank you for your help and quick reply. I just tried it out and it works!

@Miksus
Copy link
Owner

Miksus commented Sep 24, 2022

Ye, it seems I meant to merge this to master before creating the latest version: #88

It seems I forgot (and still have some timezone issues with the new tests (my time zone is different than CI's)). It seems I changed them in the docs before doing this.

So I'll fix the PR soon and merge it and then this issue should be fixed as well.

@Miksus Miksus added documentation Improvements or additions to documentation bug Something isn't working and removed bug Something isn't working labels Sep 24, 2022
@realyashnag
Copy link

Doing the same for MongoRepo fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants