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
Is there a reason why the plugin is instantiated to just get name?
New-ing a custom plugin to just get its name breaks error sanity checks in my plugin's constructor to make sure required options are not null.
Are there any problems with it being pluginName = PluginRefrence.name
If so, I can create a pull request.
The text was updated successfully, but these errors were encountered:
I believe that case exists if the plugin is actually a class.
By all means, if you can get it to work without instantiation, go for it! Please include a test to ensure that it's working
I was wondering the same thing earlier. It turned out, that the name cannot be resolved reliably unless there is an instance of the plugin itself. The name attribute is computed in the object constructor.
// [...snip...]classPlugin{constructor(worker,func,queue,job,args,options){this.name='CustomPlugin'// <-- defining default name for the custom pluginthis.worker=workerthis.queue=queuethis.func=functhis.job=jobthis.args=argsthis.options=options}// [...snip...]}
Also the deriving classes should override the name attribute in the following way (copied the example from examples/customPluginExample.js):
classMyPluginextendsNodeResque.Plugin{constructor(...args){super(...args)this.name='MyPlugin'// defining name of the plugin}beforePerform(){console.log(this.options.messagePrefix+' | '+JSON.stringify(this.args))returntrue}}
Do note this problem exists only with reference type plugins.
NB the example doesn't have the constructor defined which in turn breaks the options object. I added the constructor here for completeness.
Solution could be to create a static getter function for the plugin class. Then the name could be resolved without instantiating the class. For example:
I do not all the intricacies of JS but the following line seems weird to me
https://github.com/taskrabbit/node-resque/blob/1a2def9f46f9be5a80a5dd8630b89d23aff2ca53/lib/pluginRunner.js#L24
Is there a reason why the plugin is instantiated to just get name?
New-ing a custom plugin to just get its name breaks error sanity checks in my plugin's constructor to make sure required options are not null.
Are there any problems with it being
pluginName = PluginRefrence.name
If so, I can create a pull request.
The text was updated successfully, but these errors were encountered: