keithwhor / nodal

API Services Made Easy With Node.js
http://www.nodaljs.com/
MIT License
4.51k stars 209 forks source link

Task template and runner issues #250

Closed tranqy closed 8 years ago

tranqy commented 8 years ago

When creating a task on a new nodal setup things don't work as expected.

On a new project I generated a task

nodal g:task taskName

When I run that task there's an reference error.

npm run worker                                                ⏎

> 
> node worker.js

/node_modules/nodal/core/required/scheduler.js:10
  class Scheduler extends fxn.Scheduler {}
                          ^

ReferenceError: fxn is not defined

If I add an import for fxn in scheduler.js the error changes

npm run worker                                                ⏎

> 
> node worker.js

/tasks/dummy_task.js:7
  class DummyTask extends Nodal.Task {
                               ^

TypeError: Class extends value undefined is not a function or null
    at /tasks/dummy_task.js:7:32
    at Object.<anonymous> (/tasks/dummy_task.js:20:3)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.module.exports.LazyNodal.require (/node_modules/nodal/core/module.js:51:14)

The docs for task say they don't need to extend Task

http://www.nodaljs.com/static/docs/index.html#Task

So when I removed extends task the task fires but errors on a missing callback.. which can be gated..

How should this be working? I expected to be able to run the default worker and run, but it doesn't, which makes me unsure how to proceed with custom tasks. Should a callback be provided by nodal? What is the purpose? Is there documentation somewhere I missed?

keithwhor commented 8 years ago

You don't need to extend from Nodal.Task, and shouldn't at all. Apologies for the template being outdated. :) Will fix.

tranqy commented 8 years ago

Great thanks!

keithwhor commented 8 years ago

This is going to come in as a bugfix later today. Will close then.

keithwhor commented 8 years ago

Should be fixed now in https://github.com/keithwhor/nodal/commit/3d71acbf3b140a65cb3f8f358934fad71b6b7716