Additional invoke support

master
Drew Bednar 2 years ago
parent 7600cee487
commit d9d7b14b80

@ -1,4 +1,4 @@
MIT License Copyright (c) <year> <copyright holders> MIT License Copyright (c) 2022 Drew Bednar
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

@ -4,26 +4,10 @@ Learn Dramatiq basics
## Docker Compose Backends ## Docker Compose Backends
Since Dramatiq supports Redis and RabbitMQ as queue backends, there are two separate docker-compose files for each. These are temporary dev backends; no persistent volumes are used and there is no TLS. Since Dramatiq supports Redis and RabbitMQ as queue backends, there are two separate docker-compose files for each. The redis backend has no persistence, while the rabbit backend has a `.rabbitdata/` persistence attached as a volume mount.
Redis: ## Invoke
``` All invoke tasks reside in the `tasks.py` file at the root of the project. Use `invoke --list` or `inv -l` to print out a list of available commands. Use `inv <cmd> --help` for additional details.
docker compose -f docker-compose-redis.yml up -d
```
``` A bash complete wrapper script `autocomplete.zsh` was generated with `invoke --print-completion-script zsh > autocomplete.zsh`. Simply source this file to enable autocomplete for invoke. Use `bash` instead of `zsh` to generate a bash autocomplete wrapper.
docker compose -f docker-compose-redis.yml down
```
RabbitMQ:
It takes some time for RabbitMQ to serve requests. This does have a persistent volume.
```
docker compose -f docker-compose-rabbit.yml up -d
```
```
docker compose -f docker-compose-rabbit.yml down
```

@ -0,0 +1,34 @@
# Invoke tab-completion script to be sourced with the Z shell.
# Known to work on zsh 5.0.x, probably works on later 4.x releases as well (as
# it uses the older compctl completion system).
_complete_invoke() {
# `words` contains the entire command string up til now (including
# program name).
#
# We hand it to Invoke so it can figure out the current context: spit back
# core options, task names, the current task's options, or some combo.
#
# Before doing so, we attempt to tease out any collection flag+arg so we
# can ensure it is applied correctly.
collection_arg=''
if [[ "${words}" =~ "(-c|--collection) [^ ]+" ]]; then
collection_arg=$MATCH
fi
# `reply` is the array of valid completions handed back to `compctl`.
# Use ${=...} to force whitespace splitting in expansion of
# $collection_arg
reply=( $(invoke ${=collection_arg} --complete -- ${words}) )
}
# Tell shell builtin to use the above for completing our given binary name(s).
# * -K: use given function name to generate completions.
# * +: specifies 'alternative' completion, where options after the '+' are only
# used if the completion from the options before the '+' result in no matches.
# * -f: when function generates no results, use filenames.
# * positional args: program names to complete for.
compctl -K _complete_invoke + -f invoke inv
# vim: set ft=sh :

@ -3,10 +3,23 @@ A set of `invoke` helper commands used for this project.
""" """
from invoke import task from invoke import task
@task
def start_app(c, docs=False, extra=''):
"""Starts the app."""
print("Start the app")
if docs:
print(f"Building docs. Docs value: {extra}")
@task
def non_sense(c):
"""A non-sense command."""
print("This is non-sense")
@task @task
def start_rabbit(c): def start_rabbit(c):
"""Runs the RabbitMQ integration environment.""" """Runs the RabbitMQ integration environment."""
print("Starting RabbitMQ") print("Starting RabbitMQ")
start_app(c)
c.run("docker compose -f docker-compose-rabbit.yml up -d") c.run("docker compose -f docker-compose-rabbit.yml up -d")
@task @task
@ -25,4 +38,6 @@ def start_redis(c):
def stop_redis(c): def stop_redis(c):
"""Stops the Redis integration environent.""" """Stops the Redis integration environent."""
print("Stopping Redis") print("Stopping Redis")
c.run("docker compose -f docker-compose-redis.yml down") c.run("docker compose -f docker-compose-redis.yml down")
# TODO add docker build, tag, and push command for app

Loading…
Cancel
Save