Skip to content

Instantly share code, notes, and snippets.

Leonardo Antunes antunesleo

Block or report user

Report or block antunesleo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View routing-tasks.py
app = Celery('first_app', broker='redis://localhost/2')
# New code below
app.conf.task_routes = {
'celery_stuff.tasks.serve_a_beer': {'queue': 'beer'},
'celery_stuff.tasks.serve_a_coffee': {'queue': 'coffee'}
}
View first_app_with_serve_a_coffee.py
from celery_stuff.tasks import serve_a_beer, serve_a_coffee # Importing the task
def start_serve_a_beer():
""" Starts the execution of a celery task with the delay method.
the delay method doesn't wait the task execution be finished.
"""
serve_a_beer.delay()
print('This will be executed before the serve_a_beer task be finished')
View serve_a_coffee.py
@app.task
def serve_a_coffee():
"""
This is a celery task. Just a normal function with task decorator.
Note that we use the decorator from a celery insance.
"""
print('Getting a delicious coffee!')
sleep(1)
print("""
---------------------------------
View nginx-upstream-example
# With this, when you proxy_pass to all-apis, nginx automically will balance the requests between the servers.
upstream all-apis {
server your-ip-here:5000;
server another-ip-here:5000;
server a-third-ip-here:5000;
}
server {
View celery-serve-a-beer-logs
[2019-11-19 20:24:32,005: WARNING/ForkPoolWorker-1] Getting a delicious beer!
[2019-11-19 20:24:35,008: WARNING/ForkPoolWorker-1] ------------------------------------------------
. * .. . * *
* * @()Ooc()* o .
(Q@*0CG*O() ___
|\_________/|/ _ | | | | | / | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
View tasks.py
from time import sleep
from celery import Celery
# Creating a celery instance.
app = Celery('first_app', broker='redis://localhost/2')
@app.task
def serve_a_beer():
"""
View first_app.py
from celery_stuff.tasks import serve_a_beer # Importing the task
def start_serve_a_beer():
""" Starts the execution of a celery task with the delay method.
the delay method doesn't wait the task execution be finished.
"""
serve_a_beer.delay()
print('This will be executed before the serve_a_beer task be finished')
@antunesleo
antunesleo / rabbitmq-install.txt
Last active Jul 25, 2019
Instructions to install rabbitmq
View rabbitmq-install.txt
$ sudo apt-get install rabbitmq-server
$ sudo rabbitmqctl add_user youruser yourpassword
$ sudo rabbitmqctl add_vhost yourprojecthost
$ sudo rabbitmqctl set_user_tags youruser administrator
$ sudo rabbitmqctl set_permissions -p yourprojecthost youruser ".*" ".*" ".*"
$ sudo service rabbitmq-server restart
To use as a broker or backend on celery:
pyamqp://youruser:yourpassword@localhost:5672/yourprojecthost
View gist:1e130ef23f57667a1dd37a677c382bba
location /cache {
add_header Access-Control-Allow-Origin *;
alias /some-folder/some-another-folder;
}
View checking-if-the-user-are-online.js
window.addEventListener('load', function(e) {
if (navigator.onLine) {
console.log('We\'re online!');
} else {
console.log('We\'re offline...');
}
}, false);
window.addEventListener('online', function(e) {
console.log('And we\'re back :).');
You can’t perform that action at this time.