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

Exercise 2 of chapter 5 #27

Closed
Arturomtz8 opened this issue Aug 4, 2022 · 10 comments
Closed

Exercise 2 of chapter 5 #27

Arturomtz8 opened this issue Aug 4, 2022 · 10 comments
Assignees
Labels
question Further information is requested

Comments

@Arturomtz8
Copy link

The data persistency doesn't work with the sqlite db, I followed the steps as the book said and didn't change anything of the code. When I stop de container and run it again, it doesn't recognize my subreddit source. Also it doesn't allow put a list of subreddits as sources, it only takes the last one.

@SathyaBhat
Copy link
Collaborator

The data persistency doesn't work with the sqlite db, I followed the steps as the book said and didn't change anything of the code. When I stop de container and run it again, it doesn't recognize my subreddit source. Also it doesn't allow put a list of subreddits as sources, it only takes the last one.

can you post what commands are you running when you:

  • first start the container
  • stop & start the container?

@Arturomtz8
Copy link
Author

Arturomtz8 commented Aug 4, 2022

Sure.
Command for building the image:
docker build -t sathyabhat/newsbot-sqlite .
Command for starting the container:
docker run --rm --name newsbot-sqlite -e NBT_ACCESS_TOKEN -v newsbot-data:/data sathyabhat/newsbot-sqlite
Stop the container:
Control + C
Re-run the container:
docker run --rm --name newsbot-sqlite -e NBT_ACCESS_TOKEN -v newsbot-data:/data sathyabhat/newsbot-sqlite
Thanks a lot.

@SathyaBhat
Copy link
Collaborator

SathyaBhat commented Aug 8, 2022

I can't see to repro this error:

Built the container, and ran it as you said:

docker run --rm --name newsbot-sqlite -e NBT_ACCESS_TOKEN -v newsbot-data:/data sathyabhat/newsbot-sqlite

INFO: 2022-08-08 00:03:29,167 - <module> - Starting newsbot
INFO: 2022-08-08 00:03:31,090 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:03:35,875 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:03:37,662 - get_updates - received response: {'ok': True, 'result': []}
...
INFO: 2022-08-08 00:03:55,998 - handle_incoming_messages - Chat text received: /source docker
INFO: 2022-08-08 00:03:55,998 - handle_incoming_messages - Sources set for 7342383 to  docker
INFO: 2022-08-08 00:03:55,999 - handle_incoming_messages - Updated 1 rows
INFO: 2022-08-08 00:03:58,620 - get_updates - received response: {'ok': True, 'result': []}
^CINFO: 2022-08-08 00:04:02,206 - <module> - Received KeybInterrupt, exiting

Ctrl+C & start again

INFO: 2022-08-08 00:04:17,490 - <module> - Starting newsbot
INFO: 2022-08-08 00:04:19,304 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:04:24,090 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:04:25,874 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:04:28,962 - get_latest_news - Fetching subreddits: {sub_reddits}

image

It does fetch.

Comma separated subreddits work as well:

INFO: 2022-08-08 00:05:05,305 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:05:07,088 - handle_incoming_messages - Chat text received: /source docker, kubernetes
INFO: 2022-08-08 00:05:07,088 - handle_incoming_messages - Sources set for 7342383 to  docker, kubernetes
INFO: 2022-08-08 00:05:07,089 - handle_incoming_messages - Updated 1 rows
INFO: 2022-08-08 00:05:09,689 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:05:14,481 - get_updates - received response: {'ok': True, 'result': []}
...
INFO: 2022-08-08 00:05:16,265 - handle_incoming_messages - Chat text received: /fetch
INFO: 2022-08-08 00:05:17,073 - get_latest_news - Fetching subreddits: {sub_reddits}

You can see it works:

image

Are the subreddits private or quarantined? It might not work if that's the case, but I am happy to test out if you mention them.

For the SQLite, maybe the volume is shared with a previous run? Can you try with a fresh volume by removing the existing one

docker volume rm newsbot-data

And then trying again?

@SathyaBhat
Copy link
Collaborator

fwiw I added a commit to fix the subreddit lists not showing right 04410b6

@SathyaBhat SathyaBhat added the question Further information is requested label Aug 10, 2022
@SathyaBhat SathyaBhat self-assigned this Aug 10, 2022
@Arturomtz8
Copy link
Author

I tried removing the volume but nope, it still doesn't recognizes my sources set before when re-running the container. Nevertheless I could accomplish to assign more than one subreddit in the sources. The data persistency still is very strange because Im using the same code of the repo, and when recreating the environment and trying to fetch the news:
Screen Shot 2022-08-12 at 9 42 21

@Arturomtz8
Copy link
Author

I inspected the sqlite db using DBeaver, and it is not saving anything there. That should be the reason

@SathyaBhat
Copy link
Collaborator

I inspected the sqlite db using DBeaver, and it is not saving anything there. That should be the reason

How did you examine the sqlite DB?

@Arturomtz8
Copy link
Author

using db beaver, you select the path to the database and connect, then you can make queries, and it didn't contain my sources even I restarted the container.

@SathyaBhat
Copy link
Collaborator

I meant to ask how are you getting the location of the db. Are you doing a docker volume inspect on the database to determine the location?

Can you try using a bind mount and see that the data gets saved?

docker run --rm --name newsbot-sqlite -e NBT_ACCESS_TOKEN -v $HOME/newsbot-data:/data sathyabhat/newsbot-sqlite

@Arturomtz8
Copy link
Author

Arturomtz8 commented Aug 31, 2022

Hello, I finally knew why the volume wasn't working, the problem is the path inside the container, because in the book says that you must mount the volume like so:
-v newsbot-data:/data

But the correct path to save the newsbot.db of the container is:
/apps/subredditfetcher/data

I figured it out entering to bash and navigating to the data folder where the db is stored and using pwd.
So the correct way to ensure that data is persisted is:
-v newsbot-data:/apps/subredditfetcher/data

The full command would be:
docker run -d --rm --name reddit-bot -e NBT_ACCESS_TOKEN -v newsbot-data:/apps/subredditfetcher/data reddit-image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants