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
andconfig.servers.web.queryRouting
. These options were confusing, and generally conflicted with theconfig/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 oldautomaticRoutes
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 aget
entry for the Status, Swagger, and CreateChatRoom actions, so the examples continue to workActions 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
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
withawait 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 withconfig.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 usingdata.response
.data.response
will be removed in a future version of Actionhero.