Skip to content

feat: Redis controller correctly enqueues Resque-compatible messages

stephen requested to merge resque-messaging into main

This commit refactors and fleshes out the Redis controller with the capacity to enqueue Resque-compatible work items into a Redis queue.

This allows instances of donate-neo which:

  1. ...are configured to connect with Redis servers which are shared with
  2. ...an appropriately-configured CiviCRM instance ...to instruct CiviCRM to perform specific actions.

This is achieved by doing the following:

  1. Adding a new environment variable named APP_ENV, making it available via settings.py, then ensuring RedisController has access to it via DI (e.g., in containers.py). The value of this variable defaults to "staging", as the only other valid value for it is "prod".
  2. Generating the name of our work queue, which is [APP_ENV]_web_donations (with [APP_ENV] depending on the aforementioned env var).
  3. Ensuring our particular work queue is a member of the set "resque:queues" by SADDing it (and if it is, Redis ignores the SADD)
  4. Assembling the value for the key-value pair by constructing a specifically-formatted dict with the name of the class we're invoking, arguments for the class being called, a pseudo-random id, and a queue_time consisting of UNIX time in microseconds. (For the sake of completeness, since resque-php adds it, we also add a "prefix" key with no value to this dict.) We then json.dumps() the dict into a string as Redis requires for values in key-value pairs.
  5. Pushing our work order onto our work queue with RPUSH.

Resque workers watching the job queue will see a new item appear in the [APP_ENV]_web_donations list and retrieve it, executing the requested class method and passing it the listed arguments. This process has been tested with a locally-running Redis queue and a PHP development server running resque-php.

Merge request reports