Sending and Accessing a Payload to IronWorker

Workers are just sections of discrete, modular code that you queue tasks against. It's rare, though, that you want to run the same code repeatedly with no changes or variables. To address this, IronWorker has the concept of a "payload". The payload is the same thing, conceptually, as an argument or variable that is passed to a function, method, or command — just a piece of information you want to supply at runtime and make available in the worker itself.

Client is able to specify payload for queued or scheduled workers. Payloads are strings. But usually we suggest to use JSON format.

Table of Contents

Get Payload in a Worker

When payload is posted to a worker when using the queue or schedule API endpoints, that payload will be written to a file for your worker to use in it's working directory. The location of that file is passed to the worker using the -payload command line flag.

To get the contents of your payload, you need to:

  1. Read the -payload flag/argument using whatever your language uses to read command line flags.
  2. Open and read the file specified by the -payload flag
  3. Parse the contents of the file (for example, if your payload is JSON)

Most of our client libraries have helper methods to help with this, see your client libs docs for more information.

Other Information

Your worker will also be passed -id and -d command line arguments. The value of -id will be the ID of the task that is currently being executed, and the value of -d will be the user-writable directory that can be used for temporary storage for the duration of the task's execution.

Payload Filtering in the HUD

You can see your tasks payload in the HUD. Go to Worker project's section, click on "Tasks" tab and then on one of your workers where you use payload. Click on "Details" link on task.

HUD filters payload by the next rule. It looks for all keys on any level of nesting which contains substrings:

  • token
  • security
  • password
  • secret
  • pass
  • connectionstring
  • api_key
  • license

and change their values to [FILTERED].

Example: original payload

{
  "database": {
    "connectionstring": "postgres://usr:pass@host:port/db"
  },
  "iron": {
    "project_id": "1234567890",
    "token": "TOKEN1234"
  },
  "3rdparty_service": {
    "user": "username",
    "service_pass": "userp4ss"
  }
}

Example: payload visible through the HUD

{
  "database": {
    "connectionstring": "[FILTERED]"
  },
  "iron": {
    "project_id": "1234567890",
    "token": "[FILTERED]"
  },
  "3rdparty_service": {
    "user": "username",
    "service_pass": "[FILTERED]"
  }
}