ActionHero v24.0.0 Release Notes

Release Date: 2020-10-11 // over 3 years ago
  • ๐Ÿš€ A new major release with lots of new features!

    What's New

    node-resque v8 (#1606)

    โฑ This new version of node-resque did a lot of work to make your tasks more idempotent. It's now harder to loose jobs if your application crashes. Be sure to set config.tasks.retryStuckJobs (boolean) to enable the automatic-retrying of stuck tasks by the resque scheduler.

    From actionhero/node-resque#453

    ๐Ÿ“‡ > This PR moves to use a Lua script to atomically (within the redis srerver) both pop the job from the list and write it to the Worker's metadata.

    ๐Ÿ“ฆ > Due to the sematics of how ioredis loads and uses lua commands, this is a breaking change as this may break users who do not use the ioredis package

    Redis version >= 2.6.0 is now required

    โž• Add automaticRoutes, Remove query and simple routing (#1607)

    ๐ŸŒ Per the discussion in #1579, Actionhero is removing the options config.servers.web.simpleRouting and config.servers.web.queryRouting. These options were confusing, and generally conflicted with the config/routes.ts file. We want to be clear to new users that the "right" way to define the routes for your Actionhero APIs is in /config/routes.ts.

    ๐Ÿš€ That said, there are times when you may need to quickly build routes automatically from your actions, like when testing or deploying this core Actionhero project directly ๐Ÿ˜. For those cases, this PR adds a new option, config.servers.web.automaticRoutes. This new option is similar-ish to the old automaticRoutes option, but differs in a few key ways:

    • 0๏ธโƒฃ disabled by default. New users will not get confused about why actions are showing up automatically
    • ๐Ÿ‘ can support some/many HTTP verbs. The verb(s) you want are now declarative, ie:
      • config.servers.web.automaticRoutes = ['get']
      • config.servers.web.automaticRoutes = ['get', 'post', 'head']

    For newly generated Actionhero Projects, we will start with your config/routes.ts file including a get entry for the Status, Swagger, and CreateChatRoom actions, so the examples continue to work

    Actions can return responses to determine response types (#1610)

    ๐Ÿ— The preferred way to describe an Action's run method is now by returning an object which you want to send to your consumers. By doing this, you are building up a Typescript type which can then be used in your API to type-check API responses!

    For example:

    // src/actions/randomNumber.tsimport { Action } from "actionhero";export class RandomNumber extends Action {constructor() {super();this.name = "randomNumber";this.description = "I am an API method which will generate a random number";this.outputExample = { randomNumber: 0.123 };}async run({ connection }) {const randomNumber = Math.random();const stringRandomNumber: string = connection.localize(["Your random number is {{randomNumber}}",{ randomNumber },]);return { randomNumber, stringRandomNumber };}}
    

    Now, you can load in the action and inspect the run method's return type:

    const { RandomNumber } = await import("../../src/actions/randomNumber");type ResponseType = UnwrapPromise\<typeof RandomNumber.prototype.run\>;// now that we know the types, we can enforce that new objects match the type// this is OK!const responsePayload: ResponseType = {randomNumber: 1,stringRandomNumber: "some string",};// this fails compilation (missing stringRandomNumber):const responsePayload: ResponseType = {randomNumber: 1,};
    

    The type information is also available to your IDE

    Screen Shot 2020-10-06 at 4 33 30 PM

    Setting data.response in the action is still possible, but now it will be discouraged by the class Action, which expects the run method to return an object or null.

    Actionhero now includes the helper types <UnwrapPromise> and <AssertEqualType> for these types of use cases.

    โšก๏ธ Other Updates:

    • cache.keys can be provided an optionalScopePrefix (#1612)
    • Do not load routes from Actionhero core (#1613)
    • Replace require with await import where possible (#1614)

    Migration Path

    ๐Ÿ†• New Config Options which should be added:

    • ๐ŸŒ config.servers.web.automaticRoutes = []
    • ๐Ÿ‘ท config.tasks.retryStuckJobs = false

    ๐Ÿšš Config Options which should be removed:

    • ๐ŸŒ config.servers.web.simpleRouting (spiritually replaced with config.servers.web.automaticRoutes)
    • ๐ŸŒ config.servers.web.queryRouting (depreciated)

    ๐Ÿšš And if you want to use the new Typescript features, change your Actions to return the response you want to send rather than using data.response. data.response will be removed in a future version of Actionhero.