1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
import uuid |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
def get_queue_name(queue_name_base, queue_name_suffix, add_random_uuid_to_suffix=True): |
20
|
|
|
""" |
21
|
|
|
Get a queue name based on base name and suffix. You can also specify if you need a random |
22
|
|
|
UUID at the end of the final name generated. Format returned is |
23
|
|
|
``queue_name_base.queue_.queue_name_suffix-UUID``. |
24
|
|
|
|
25
|
|
|
:param queue_name_base: Base name for the queue. |
26
|
|
|
:type queue_name_base: ``str`` |
27
|
|
|
|
28
|
|
|
:param queue_name_suffix: Base string for the suffix. |
29
|
|
|
:type queue_name_suffix: ``str`` |
30
|
|
|
|
31
|
|
|
:param add_random_uuid_to_suffix: A boolean to indicate a UUID suffix to be |
32
|
|
|
added to name or not. |
33
|
|
|
:type add_random_uuid_to_suffix: ``boolean`` |
34
|
|
|
|
35
|
|
|
:rtype: ``str`` |
36
|
|
|
""" |
37
|
|
|
if not queue_name_base: |
38
|
|
|
raise ValueError('Queue name base cannot be empty.') |
39
|
|
|
|
40
|
|
|
if not queue_name_suffix: |
41
|
|
|
return queue_name_base |
42
|
|
|
|
43
|
|
|
queue_suffix = queue_name_suffix |
44
|
|
|
if add_random_uuid_to_suffix: |
45
|
|
|
# Pick last 10 digits of uuid. Arbitrary but unique enough. Long queue names |
46
|
|
|
# might cause issues in RabbitMQ. |
47
|
|
|
u_hex = uuid.uuid4().hex |
48
|
|
|
uuid_suffix = uuid.uuid4().hex[len(u_hex) - 10:] |
49
|
|
|
queue_suffix = '%s-%s' % (queue_name_suffix, uuid_suffix) |
50
|
|
|
|
51
|
|
|
queue_name = '%s.%s' % (queue_name_base, queue_suffix) |
52
|
|
|
return queue_name |
53
|
|
|
|