Celery Interview Question-Answer

Q.1 Celery is a package available in __________.

       A. Pandas

       B. NumPy

       C. PyPI

       D. SciPy

Ans : PyPI


Q.2 To run RabbitMQ in the background, use ________.

       A. $ sudo rabbitmq-server -background

       B. $ sudo rabbitmq-server -b

       C. $ sudo rabbitmq-server -detached

       D. $ sudo rabbitmq-server -attach

Ans : $ sudo rabbitmq-server -detached


Q.3 A client process ___________.

       A. subscribes to task queues to perform work

       B. puts work requests into queues

       C. puts work requests into queues and fetches results from the backend

       D. fetches results from the backend

       E. All the options

Ans : puts work requests into queues and fetches results from the backend


Q.4 Celery protocol can be implemented in any language.

       A. True

       B. False

Ans : True


Q.5 Using rpc:// result backend, two processes can wait for the same result.

       A. True

       B. False

Ans : False


Q.6 Name the broker in the following.

app = Celery(‘tasks’, broker=’pyamqp://guest@localhost//’).

       A. Redis

       B. RabbitMQ

       C. Amazon SQS

       D. None of the options

Ans : RabbitMQ


Q.7 If app=celery(), task is created using _______ decorator.

       A. app

       B. @app.task

       C. @task.app

       D. All the options

Ans : @app.task


Q.8 If a task raises an exception, we can override it using __________.

       A. result.get(propagate=True)

       B. result.get(propagate=False)

       C. result.get(exception=True)

       D. result.get(exception=False)

Ans : result.get(propagate=False)


Q.9 If the following configuration is used, which of the following is used for broker and backend?

broker_url = ‘pyamqp://’
result_backend = ‘rpc://’.

       A. Broker is Redis, backend is RabbitMQ

       B. Both broker and backend are RabbitMQ

       C. Both broker and backend are Redis

       D. Broker is RabbitMQ, backend is Redis

Ans : Both broker and backend are RabbitMQ


Q.10 Which of the following calling APIs is/are supported by celery task instances?

       A. calling

       B. delay

       C. apply_async

       D. All the options

Ans : All the options


Q.11 Consider the following.

<<< from celery import Celery
<<< app = Celery()
What does app have?

       A. Memory address of the object

       B. Name of the current main module

       C. Name of the app class

       D. All the options

Ans : Memory address of the object


Q.12 Celery has the following defined default result states, except _______.

       A. STARTED

       B. RUNNING

       C. PENDING

       D. RETRY

Ans : RUNNING


Q.13 Consider a task T. Write the code to execute in 10 seconds from now, specified using ETA.

       A. T.apply_async(ETA=now + timedelta(seconds=10))

       B. T.apply_async(ETA=now + timedelta(10))

       C. T.apply_async(eta=now + timedelta(seconds=10))

       D. T.apply_async(countdown=10)

Ans : T.apply_async(ETA=now + timedelta(seconds=10))


Q.14 Consider a file tasks.py with:

@app.task
def add(x, y):
  return x + y
After executing:

from tasks import add
What will be the output of:

<<< add.name

       A. error

       B. tasks.add’

       C. name not defined

       D. None of the options

Ans : tasks.add’


Q.15 Celery automatically retries sending messages in the event of a connection failure.

       A. True

       B. False

Ans : True


Q.16 celeri multi stores information about workers.

       A. True

       B. False

Ans : False


Q.17 If we add the following in celery configuration

task_annotations = {
  ‘tasks.add’: {‘rate_limit’: ’10/m’}
}

what does it mean

       A. mechanism to low prioritize misbehaving queues

       B. the task rate limit is set

       C. Only 10 tasks of this type can be processed in a minute

       D. All the options

Ans : All the options


Q.18 consider a task T. Write a code to execute in 30 seconds from now, but expires after 3 minutes.

       A. T.apply_async(countdown=30, expires=180)

       B. T.apply_async(countdown=30, expires=3min)

       C. T.apply_async(timedelta(seconds=30), expires=180)

       D. T.apply_async(countdown=180, expires=30)

Ans : T.apply_async(countdown=30, expires=180)


Q.19 To list active queues for the worker w1, use

       A. app.control.inspect().active_queues()

       B. app.control.inspect([‘w1.local’]).active_queues()

       C. both

       D. None

Ans : app.control.inspect([‘w1.local’]).active_queues()


Q.20 What is the default queue in celery

       A. Redis

       B. default

       C. RabbitMQ

       D. celery

Ans : celery


Q.21 Let

i = app.control.inspect()
To get a list of registered tasks, use

       A. i.registered()

       B. i.active()

       C. i.scheduled()

       D. i.reserved()

       E. All the options

Ans : i.registered()


Q.22 To add a consumer to a queue named q1, use

       A. app.control.add_consumer(‘q1’, reply=True)

       B. app.control.add_consumer(‘q1’, reply=False)

       C. app.control.add_consumer(‘q1’, reply=True, destination=[‘worker1@gmail.com’])

       D. app.control.add_consumer(‘q1’, reply=False, destination=[‘worker1@gmail.com’])

Ans : app.control.add_consumer(‘q1’, reply=True)


Q.23 Let

i = app.control.inspect()
To get a list of reserved tasks, use

       A. i.reserved()

       B. i.registered()

       C. i.scheduled()

       D. i.active()

Ans : i.reserved()


Q.24 To divide an iterable work into pieces, use

       A. starmap

       B. chunks

       C. piece

       D. chord

Ans : chunks


Q.25 Consider a chain

res = chain(add.s(4, 4), mul.s(8), mul.s(10))()

where add is defined as a+b and mul is defined as a*b. How can we get intermediate parent results

       A. res.parent.parent

       B. res.parent.get()

       C. res.parent.parent.get()

       D. All the options

Ans : res.parent.parent.get()


Q.26 Map and star-map differ from group in what ways?

       A. the operation is parallel

       B. only one task message is sent AND the operation is sequential

       C. only one task message is sent AND the operation is parallel

       D. the operation is sequential

       E. only one task message is sent

Ans : only one task message is sent AND the operation is sequential


Q.27 (group(add.s(i, i) for i in xrange(10)) | xsum.s())().get() is an example of

       A. chain

       B. group

       C. chunk

       D. chord

Ans : chain


Q.28 The GroupResult takes a list of AsyncResult instances and has the following operations.

       A. join()

       B. revoke()

       C. ready()

       D. successful()

       E. All the options

Ans : All the options


Leave a Comment