faastjs / faast.js

Serverless batch computing made simple.
https://faastjs.org
Apache License 2.0
1.48k stars 42 forks source link

I have a problem : "Cannot find any-observable implementation nor global.Observable" #582

Closed gabrieltorreswm closed 3 years ago

gabrieltorreswm commented 3 years ago

CloudWatch has thrown this error when tried to run the lambda function. I am using an approach serverless with AWS.

I am using the Serverless Framework to push my changes

Cannot find any-observable implementation nor global.Observable. You must install polyfill or call require(\"any-observable/register\") with your preferred implementation, e.g. require(\"any-observable/register\")('rxjs') on application load prior to any require(\"any-observable\").

acchou commented 3 years ago

Most likely you're probably trying to include faast.js on the remote side (i.e. within the lambda function code), which isn't supported: https://faastjs.org/docs/errors#cannot-find-any-observable

I don't think there's much of a use case for combining faast.js with the Serverless Framework. If you could clarify what you're trying to do I could provide an opinion.

gabrieltorreswm commented 3 years ago

Thanks, I figure out what was the problems. I used in my sheet serverless a plugin that makes conflict with faastJs, I was to remove it, "serverless-plugin-optimize"

but now I have other problems,

look at this :

Screen Shot 2021-01-04 at 13 14 00

Unhandled Promise Rejection
{ "errorType": "Runtime.UnhandledPromiseRejection", "errorMessage": "Error: ENOENT: no such file or directory, mkdir '/home/sbx_user1051'", "reason": { "errorType": "Error", "errorMessage": "ENOENT: no such file or directory, mkdir '/home/sbx_user1051'", "code": "ENOENT", "errno": -2, "syscall": "mkdir", "path": "/home/sbx_user1051", "stack": [ "Error: ENOENT: no such file or directory, mkdir '/home/sbx_user1051'" ] }, "promise": {}, "stack": [ "Runtime.UnhandledPromiseRejection: Error: ENOENT: no such file or directory, mkdir '/home/sbx_user1051'", " at process. (/var/runtime/index.js:35:15)", " at process.emit (events.js:314:20)", " at process.EventEmitter.emit (domain.js:483:12)", " at processPromiseRejections (internal/process/promises.js:209:33)", " at processTicksAndRejections (internal/process/task_queues.js:98:32)" ] }

just happened when used this code line:

const faastFunctions = await faast("aws", methods);

acchou commented 3 years ago

I'm unable to reproduce this; can you provide a self-contained example (complete source code)?

gabrieltorreswm commented 3 years ago

I'm unable to reproduce this; can you provide a self-contained example (complete source code)?

`const util = require('util') const methods = require('./common/methods') const papa = require('papaparse') const {faast,faastAws} = require('faastjs')

module.exports.handler = async function(event) { console.log("handler processor") //setting up fasstjs const faastFunctions = await faast("aws", methods); //faastAws(faastFunctions,"/path",{ region: "sa-east-1" })

//console.log('Files bucket event ', util.inspect(event, true, 10)) const s3Info = event.requestPayload.Records[0].s3

// Download file from S3 and parse it!
const key = s3Info.object.key
console.log('File key: ', key)
const downloading = faastFunctions.methods.getObject(key)
const file = downloading.Body.toString() // utf-8 string

const parsed = papa.parse(file, { delimiter: '|', skipEmptyLines: true })

if (parsed.data.errors) {
    console.log('Errors: ', parsed.data.errors)
    return
}

if (parsed.data.length > 0) {
    console.log('Processed rows: ', parsed.data.length)
    console.log('schema info ', parsed.data)

    // Get the last sequence number
    const lastSequence = faastFunctions.methods.getSequence()
    const sequence = lastSequence[0].secuencia_actual

    // Total sequence value after this operation ends
    const totalSequence = sequence + parsed.data.length

    // 1. Map the rows array and open a connection to store each row
    let counter = sequence;
    const storing = parsed.data.map(async row => {
        // console.log('Current row ', row)
        counter += 1           
        // * Store structured data in DB
        // TODO: Si hay error restar 1 al counter
        try {            
            return await faastFunctions.methods.storeLine(row, counter)
        } catch(error) {
            // If an error occurs, returns back that number
            console.log('Error storing row ', error)
        }
    })

    console.log('Array promise before', storing.length)
    const promise = await Promise
            .all(storing)
                .then(res => {
                    console.log("Res promise",res)
            }, reason=>{
                console.log("reson promise",reason)
            }
    )
    console.log('Promise done ', promise.length)

    // Let's update sequence number
    try {
        const updateSequence = await faastFunctions.methods.updateSequence(counter)
        // console.log('update sequence ', updateSequence)
        await faastFunctions.cleanup();
        const cost = await faastFunctions.costSnapshot();
        const total = cost.total()
        console.log(total);
        return 'done!'
    } catch(error) {
        console.log('error ', error) // TODO: Alert via WA
        return 'error!'
    }

} else {
    console.log('No data: ', parsed.data)
    return 'no data in file'
}

}`

acchou commented 3 years ago

It looks like you're trying to define a lambda function handler and use faast.js within it, perhaps deploying this code via the Serverless framework? That would be a misunderstanding of how faast.js is supposed to be used. Instead, write code that runs locally, not on lambda, to execute faast.js. Only the code in the methods import should run on lambda. The code here should run on your local machine.

If you provide a public repository with a small example I'm sure we can get it to work, and you can build up from there.

acchou commented 3 years ago

Here's a suggestion: take one of the examples (https://github.com/faastjs/examples) and try to run it. Then add your code in from there, step by step, until something breaks and you'll see more clearly which step is broken.

gabrieltorreswm commented 3 years ago

okay, thanks Andy Chao for your clarification.

Let me understand, faastjs only work locally? cant I used FAAST how an approach for resolve a problem with a batch processor?

you could tell me something about this.

Screen Shot 2021-01-04 at 15 01 56

acchou commented 3 years ago

Faast.js runs locally but creates the remote lambda functions automatically. faast.js will create the serverless function for you; you don't need to do it with the serverless framework.

gabrieltorreswm commented 3 years ago

ohhhhh okay !! Thank you soo much !!