Skip to content
Mike Perham edited this page Nov 12, 2019 · 25 revisions

Faktory Enterprise allows the developer to declare a set of jobs to perform as a group and fire a callback when all of those jobs are complete or successful. This is known as a batch of jobs.

Declaring a Batch and Callback

Use the BATCH command to start a batch with a JSON blob that represents either/both a success or complete callback job. Each batch has a unique BID to identify it.

bid = BATCH {"description":"An optional description for the Web UI",
             "success":{"jobtype":"MySuccessCallback","args":[user_id],"queue":"critical"},
             "complete":...}
  jid = PUSH ...
  jid = PUSH ...
COMMIT

Although this simple example doesn't show it, you may nest batches arbitrarily deep. The initial batch data has a TTL of 30 minutes and will expire if your code does not call COMMIT. Each job you push will have the Batch BID placed into its "custom" data hash.

Reopening a Batch

You can dynamically add more jobs or nested, child batches to a batch by reopening it:

BATCH bid
  jid = PUSH ...
  childbid = BATCH ...
    childjid = PUSH ...
  COMMIT
COMMIT

Callbacks

The initial batch creation must include a success and/or a complete job callback. A callback is job that Faktory will enqueue once the batch of jobs has completed or succeeded.

Status

You can retrieve the status of a batch using the BSTATUS command. This returns a JSON blob of data associated with the batch:

BSTATUS bid
{"bid":<bid>,"total":17,"pending":14,"failed":3","created_at":"2019-11-18T13:48:25Z","description":"..."}
Clone this wiki locally