cubehouse / themeparks

Unofficial API for accessing ride wait times and schedules for Disneyland, Disney World, Universal Studios, and many more parks
MIT License
542 stars 125 forks source link

5.1.0 Issue using firebase. #175

Closed jorrharris closed 5 years ago

jorrharris commented 5 years ago

Park Disney Resort California Adventure Disney Resort Magic Kingdom

Context

Describe the bug I am trying to use the library with firebase. It was working with the older version before disney took down their api. But now I get this error when deploying my function and I don't really know what to do because I've never used SQLite with firebase and don't really understand what it's doing...

Error:

Error: Failed to setup sqlite database: Error: SQLITE_READONLY: attempt to write a readonly database
    at SetupDB.then.then.catch (/user_code/node_modules/themeparks/lib/cache.js:217:17)

Here is my code:

const functions = require("firebase-functions");
const admin = require("firebase-admin");

const Themeparks = require("themeparks");

admin.initializeApp(functions.config().firebase);
const db = admin.firestore();

const disneyMagicKingdom = new Themeparks.Parks.DisneylandResortMagicKingdom();
const disneyCaliforniaAdventure = new Themeparks.Parks.DisneylandResortCaliforniaAdventure();

exports.updateDatabase = functions.pubsub.topic("rideranker").onPublish(() => {
  MY FUNCTION CODE GOES IN HERE WHERE I JUST BASICALLY CALL GETWAITTIMES() AND STORE IT IN MY FIRESTORE DATABASE...
});

Output In my firebase logs this error appears:

Error: Failed to setup sqlite database: Error: SQLITE_READONLY: attempt to write a readonly database
    at SetupDB.then.then.catch (/user_code/node_modules/themeparks/lib/cache.js:217:17)

Does anyone know how to solve this or why I am getting this error?

DougSisk commented 5 years ago

I haven't worked with Firebase before, but try explicitly setting your SQLite database location: Themeparks.Settings.Cache = __dirname + "/themeparks.db";

jorrharris commented 5 years ago

This doesn't seem to fix the issue. The '/themeparks.db' file is being created, but there is nothing inside of it. For some reason it is read only I'm guessing, which is causing the issue?

cubehouse commented 5 years ago

I'm afraid I don't know how Firebase works. Is it a lambda function service, or something else? The library doesn't work well with lambda style hosting because the new API really needs a persistent data storage.

Can you test locally to ensure your setup works fine and can populate the database? Otherwise, try and write some other files to your local Firebase instance to figure out what is not working. If that works, try making your own sqlite3 database to debug why the sqlite3 library isn't running in your environment.

jorrharris commented 5 years ago

It's basically just a node.js server that you can run cloud functions on. I tested the code on my local environment and it works just fine. What I am basically doing is trying to pull the waitTime info from the library and store it in my own firebase database. Would there be a better way to do this?

jorrharris commented 5 years ago

@cubehouse After doing some reading, It looks like you can't be writing files to the local firebase file system because of the way it works. Is there anyway to get the wait times without writing to that themeparks.db file (like how v4.x.x) did things?

ImAnAutie commented 5 years ago

I've only just started with firebase functions but it appears you can write to /tmp but it's per function invocation. Have you tired that?

jorrharris commented 5 years ago

@OkoWsc I added this:

Themeparks.Settings.Cache = __dirname + "/tmp/themeparks.db";

If that's what you mean? It didn't seem to do anything but produce another error in addition to the one I was already getting before (So now I'm getting two errors):

Error: function crashed out of request scope Function invocation was interrupted.
ImAnAutie commented 5 years ago

Based on Google's docs the temp is /tmp not in the application running directory.

Try

Themeparks.Settings.Cache = "/tmp/themeparks.db";

jorrharris commented 5 years ago

@OkoWsc This worked, thank you very much, you are a life saver!