Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pikatasks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
django
pikatasks
Commits
5d66db92
Commit
5d66db92
authored
7 years ago
by
Art
Browse files
Options
Downloads
Patches
Plain Diff
Add pika 1.0.0b1 compatibility
parent
73c09624
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pikatasks/__init__.py
+6
-1
6 additions, 1 deletion
pikatasks/__init__.py
pikatasks/worker.py
+13
-6
13 additions, 6 deletions
pikatasks/worker.py
with
19 additions
and
7 deletions
pikatasks/__init__.py
+
6
−
1
View file @
5d66db92
...
@@ -88,7 +88,12 @@ def rpc(_task_name, **kwargs):
...
@@ -88,7 +88,12 @@ def rpc(_task_name, **kwargs):
channel
=
conn
.
channel
()
channel
=
conn
.
channel
()
channel
.
confirm_delivery
()
channel
.
confirm_delivery
()
# start waiting for RPC response (required before sending a request with reply-to)
# start waiting for RPC response (required before sending a request with reply-to)
channel
.
basic_consume
(
callback_result
,
queue
=
"
amq.rabbitmq.reply-to
"
,
no_ack
=
True
)
if
pika
.
__version__
>=
"
1.0
"
:
# multiple breaking changes in version 1.0.0b1
# if this is broken again, also fix the other basic_consume in this project
channel
.
basic_consume
(
queue
=
"
amq.rabbitmq.reply-to
"
,
on_message_callback
=
callback_result
,
auto_ack
=
True
)
else
:
channel
.
basic_consume
(
consumer_callback
=
callback_result
,
queue
=
"
amq.rabbitmq.reply-to
"
,
no_ack
=
True
)
# send a request
# send a request
channel
.
basic_publish
(
channel
.
basic_publish
(
exchange
=
settings
.
CLIENT_EXCHANGE_NAME
,
exchange
=
settings
.
CLIENT_EXCHANGE_NAME
,
...
...
This diff is collapsed.
Click to expand it.
pikatasks/worker.py
+
13
−
6
View file @
5d66db92
import
multiprocessing
import
multiprocessing
from
queue
import
Empty
from
.
import
settings
from
.
import
utils
import
logging
import
logging
import
time
import
time
import
signal
import
signal
import
os
import
os
from
.
import
django_compat
import
pika
from
pika.exceptions
import
AMQPChannelError
,
AMQPConnectionError
from
queue
import
Empty
from
datetime
import
datetime
from
datetime
import
datetime
from
.
import
settings
from
.
import
utils
from
.
import
django_compat
MSG_STOP
=
"
MSG_STOP
"
MSG_STOP
=
"
MSG_STOP
"
...
@@ -133,8 +135,13 @@ def _task_process(tasks, control_queue, parent_pid):
...
@@ -133,8 +135,13 @@ def _task_process(tasks, control_queue, parent_pid):
try
:
try
:
callback
=
getattr
(
task
,
"
as_callback
"
,
None
)
callback
=
getattr
(
task
,
"
as_callback
"
,
None
)
assert
callback
and
callable
(
callback
),
"
Not a valid task: {0}
"
.
format
(
task
)
assert
callback
and
callable
(
callback
),
"
Not a valid task: {0}
"
.
format
(
task
)
channel
.
basic_consume
(
callback
,
queue
=
task
.
task_queue
)
if
pika
.
__version__
>=
"
1.0
"
:
subprocess_logger
.
debug
(
log_prefix
+
"
Registered task {t} on queue {q}
"
.
format
(
t
=
task
.
task_name
,
q
=
task
.
task_queue
))
# multiple breaking changes in version 1.0.0b1
# if this is broken again, also fix the other basic_consume in this project
channel
.
basic_consume
(
queue
=
task
.
task_queue
,
on_message_callback
=
callback
)
else
:
channel
.
basic_consume
(
consumer_callback
=
callback
,
queue
=
task
.
task_queue
)
logger
.
debug
(
"
Registered task {t} on queue {q}
"
.
format
(
t
=
task
.
task_name
,
q
=
task
.
task_queue
))
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
"
Could not register task {t}. {e.__class__.__name__}: {e}
"
.
format
(
t
=
task
,
e
=
e
))
logger
.
error
(
"
Could not register task {t}. {e.__class__.__name__}: {e}
"
.
format
(
t
=
task
,
e
=
e
))
control_beat
()
# initial
control_beat
()
# initial
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment