feat: Redis controller correctly enqueues Resque-compatible messages
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:
- ...are configured to connect with Redis servers which are shared with
- ...an appropriately-configured CiviCRM instance ...to instruct CiviCRM to perform specific actions.
This is achieved by doing the following:
- Adding a new environment variable named APP_ENV, making it available
via
settings.py
, then ensuringRedisController
has access to it via DI (e.g., incontainers.py
). The value of this variable defaults to "staging", as the only other valid value for it is "prod". - Generating the name of our work queue, which is
[APP_ENV]_web_donations
(with [APP_ENV] depending on the aforementioned env var). - Ensuring our particular work queue is a member of the set
"resque:queues" by
SADD
ing it (and if it is, Redis ignores theSADD
) - 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-randomid
, and aqueue_time
consisting of UNIX time in microseconds. (For the sake of completeness, sinceresque-php
adds it, we also add a "prefix" key with no value to this dict.) We thenjson.dumps()
the dict into a string as Redis requires for values in key-value pairs. - 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
.