You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm starting a new project with TypeScript and currently experimenting with Comedy as a solution for scaling the application.
I ran into an issue with the way Resources are serialized and sent to the forked process which is causing a lot of headaches and seems like a big limitation (if I'm understanding this correctly).
The original Resource definition is as follows:
import{ActorSystem,ResourceDefinition}from'comedy';import{getResource}from'../helpers/test';import{ComedyResource}from'../decorators/ComedyResource';
@ComedyResource('TestResource')exportdefaultclassTestResourceimplementsResourceDefinition<string>{destroy(): Promise<void>|void{// nothing to do herereturnundefined;}getResource(): string{// return from an imported function as a testreturngetResource();}initialize(system: ActorSystem): Promise<void>|void{// nothing to do herereturnundefined;}}
But what is sent to the child process (in the create-actor message) is:
class TestResource {
destroy() {
// nothing to do here
return undefined;
}
getResource() {
// return from an imported function as a test
return test_1.getResource();
}
initialize(system) {
// nothing to do here
return undefined;
}
}; TestResource;
As you can see, the imports are all missing and there is no way this can work.
@Zephyrrus noticed that you can use require() inside the definition and to import things, but they are imported from the wrong working directory and therefore don't resolve properly.
As a workaround I considered creating dummy "shells" that would dynamically load the correct file (from disk) with require(), but that sounds very cumbersome to maintain.
Is there any solution to this? Am I missing something?
The text was updated successfully, but these errors were encountered:
I think you need to define the resource via a path instead of passing the object itself.
For my resources and actors I create them in a file like this:
import{ResourceDefinition,ActorSystem}from"comedy";importKnexfrom"knex";importfsfrom"fs";exportclassKnexResourceimplementsResourceDefinition<Knex>{// this resource is in a package called @pct-digital/knex-db-resourcestaticRESOURCE_PATH="@pct-digital/knex-db-resource/dist/KnexDbResourceModule";log: any;knex: Knex=nullasany;asyncinitialize(system: ActorSystem){this.log=system.getLog();this.log.info("init KnexResource");letknexConfig=(systemasany).options.config.knex;if(knexConfig==null){this.log.error("Cannot initialize KnexResource, the global configuration must contain a knex property!");}this.log.info("Initializing knex.js pool");this.knex=Knex(knexConfig);letresult=awaitthis.knex.raw("SELECT 1");if(result.rowCount!==1||result.rows.length!==1){this.log.error("knex pool test failed!");}else{this.log.info("knex pool setup completed!");}}destroy(){this.log.info("Destroying knex.js pool");returnthis.knex.destroy();}getName(){return"KnexResource";}getResource(){returnthis.knex;}}
Then I add an extra file from this this actually will be loaded by comedy:
I've not found a way to use the file that contains the normal "export class KnexResource" directly, the path I use to define the resource has to point to the file that does module.exports = ...
Hello!
I'm starting a new project with TypeScript and currently experimenting with Comedy as a solution for scaling the application.
I ran into an issue with the way Resources are serialized and sent to the forked process which is causing a lot of headaches and seems like a big limitation (if I'm understanding this correctly).
The original Resource definition is as follows:
But what is sent to the child process (in the
create-actor
message) is:As you can see, the imports are all missing and there is no way this can work.
@Zephyrrus noticed that you can use
require()
inside the definition and to import things, but they are imported from the wrong working directory and therefore don't resolve properly.As a workaround I considered creating dummy "shells" that would dynamically load the correct file (from disk) with require(), but that sounds very cumbersome to maintain.
Is there any solution to this? Am I missing something?
The text was updated successfully, but these errors were encountered: