How to use the actionhero.Action function in actionhero

To help you get started, we’ve selected a few actionhero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github actionhero / actionhero-angular-bootstrap-cors-csrf / actions / status.js View on Github external
'use strict'

const ActionHero = require('actionhero')
const path = require('path')
const packageJSON = require(path.normalize(path.join(__dirname, '..', 'package.json')))

// These values are probably good starting points, but you should expect to tweak them for your application
const maxEventLoopDelay = process.env.eventLoopDelay || 10
const maxMemoryAlloted = process.env.maxMemoryAlloted || 200
const maxResqueQueueLength = process.env.maxResqueQueueLength || 1000

module.exports = class RandomNumber extends ActionHero.Action {
  constructor () {
    super()
    this.name = 'status'
    this.description = 'I will return some basic information about the API'
    this.outputExample = {
      id: '192.168.2.11',
      actionheroVersion: '9.4.1',
      uptime: 10469
    }
  }

  async checkRam (data) {
    const consumedMemoryMB = Math.round(process.memoryUsage().heapUsed / 1024 / 1024 * 100) / 100
    data.response.consumedMemoryMB = consumedMemoryMB
    if (consumedMemoryMB > maxMemoryAlloted) {
      data.response.nodeStatus = data.connection.localize('Unhealthy')
github actionhero / actionhero-tutorial / actions / status.js View on Github external
'use strict'

const ActionHero = require('actionhero')
const path = require('path')
const packageJSON = require(path.normalize(path.join(__dirname, '..', 'package.json')))

// These values are probably good starting points, but you should expect to tweak them for your application
const maxEventLoopDelay = process.env.eventLoopDelay || 10
const maxMemoryAlloted = process.env.maxMemoryAlloted || 500
const maxResqueQueueLength = process.env.maxResqueQueueLength || 1000

module.exports = class RandomNumber extends ActionHero.Action {
  constructor () {
    super()
    this.name = 'status'
    this.description = 'I will return some basic information about the API'
    this.outputExample = {
      id: '192.168.2.11',
      actionheroVersion: '9.4.1',
      uptime: 10469
    }
  }

  async checkRam (data) {
    const consumedMemoryMB = Math.round(process.memoryUsage().heapUsed / 1024 / 1024 * 100) / 100
    data.response.consumedMemoryMB = consumedMemoryMB
    if (consumedMemoryMB > maxMemoryAlloted) {
      data.response.nodeStatus = data.connection.localize('Unhealthy')
github actionhero / actionhero-tutorial / actions / showDocumentation.js View on Github external
'use strict'
const ActionHero = require('actionhero')

module.exports = class ShowDocumentation extends ActionHero.Action {
  constructor () {
    super()
    this.name = 'showDocumentation'
    this.description = 'return API documentation'
  }

  outputExample () {
    return {
      documentation: {
        cacheTest: {
          1: {
            name: 'cacheTest',
            version: 1,
            description: 'I will test the internal cache functions of the API',
            inputs: {
              key: {
github actionhero / actionhero-tutorial / actions / createChatRoom.js View on Github external
'use strict'
const ActionHero = require('actionhero')

module.exports = class CreateChatRoom extends ActionHero.Action {
  constructor () {
    super()
    this.name = 'createChatRoom'
    this.description = 'I will create a chatroom with the given name'
    this.inputs = {
      name: {
        required: true
      }
    }
  }

  async run ({ params, response }) {
    const { chatRoom } = ActionHero.api
    response.didCreate = await chatRoom.add(params.name)
  }
}
github actionhero / actionhero-angular-bootstrap-cors-csrf / actions / showDocumentation.js View on Github external
'use strict'
const ActionHero = require('actionhero')

module.exports = class ShowDocumentation extends ActionHero.Action {
  constructor () {
    super()
    this.name = 'showDocumentation'
    this.description = 'return API documentation'
    this.middleware = ['logged-in-session']
  }

  outputExample () {
    return {
      documentation: {
        status: {
          1: {
            name: 'status',
            version: 1,
            description: 'I will return some basic information about the API',
            inputs: {