本文整理汇总了Python中pulp.server..tasks._delete_worker函数的典型用法代码示例。如果您正苦于以下问题:Python _delete_worker函数的具体用法?Python _delete_worker怎么用?Python _delete_worker使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_delete_worker函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_entry_for_worker_does_not_raise_exception
def test_no_entry_for_worker_does_not_raise_exception(self):
self.mock_resources.filter_workers.return_value = []
try:
tasks._delete_worker('worker1')
except Exception:
self.fail('_delete_worker() on a Worker that is not in the database caused an '
'Exception')
示例2: test_no_entry_for_worker_does_not_raise_exception
def test_no_entry_for_worker_does_not_raise_exception(self, mock_worker_objects):
mock_worker_objects.get.return_value = []
try:
tasks._delete_worker('worker1')
except Exception:
self.fail('_delete_worker() on a Worker that is not in the database caused an '
'Exception')
示例3: initialize_worker
def initialize_worker(sender, instance, **kwargs):
"""
This function performs all the necessary initialization of the Celery worker.
It starts by cleaning up old state if this worker was previously running, but died unexpectedly.
In such cases, any Pulp tasks that were running or waiting on this worker will show incorrect
state. Any reserved_resource reservations associated with the previous worker will also be
removed along with the worker entry in the database itself. The working directory specified in
/etc/pulp/server.conf (/var/cache/pulp/<worker_name>) by default is removed and recreated. This
is called early in the worker start process, and later when it's fully online, pulp_celerybeat
will discover the worker as usual to allow new work to arrive at this worker. If there is no
previous work to cleanup, this method still runs, but has no effect on the database.
After cleaning up old state, it ensures the existence of the worker's working directory.
Lastly, this function makes the call to Pulp's initialization code.
It uses the celeryd_after_setup signal[0] so that it gets called by Celery after logging is
initialized, but before Celery starts to run tasks.
[0] http://celery.readthedocs.org/en/latest/userguide/signals.html#celeryd-after-setup
:param sender: The hostname of the worker
:type sender: basestring
:param instance: The Worker instance to be initialized (unused)
:type instance: celery.apps.worker.Worker
:param kwargs: Other params (unused)
:type kwargs: dict
"""
initialization.initialize()
tasks._delete_worker(sender, normal_shutdown=True)
# Create a new working directory for worker that is starting now
common_utils.create_worker_working_directory(sender)
示例4: test_cancels_all_found_task_status_objects
def test_cancels_all_found_task_status_objects(self):
mock_task_id_a = mock.Mock()
mock_task_id_b = mock.Mock()
self.mock_task_status.objects.return_value = [{'task_id': mock_task_id_a},
{'task_id': mock_task_id_b}]
tasks._delete_worker('worker1')
self.mock_cancel.assert_has_calls([mock.call(mock_task_id_a), mock.call(mock_task_id_b)])
示例5: test__delete_worker_normal_shutdown_true
def test__delete_worker_normal_shutdown_true(self, mock_logger, mock_underscore):
"""
Call _delete_worker() with the normal_shutdown keyword argument set to True. This should
not make any calls to _() or logger().
"""
tasks._delete_worker('does not exist Worker name')
self.assertTrue(not mock_underscore.called)
self.assertTrue(not mock_logger.called)
示例6: test_removes_the_worker
def test_removes_the_worker(self, mock_worker_objects):
mock_document = mock.Mock()
mock_get = mock.Mock()
mock_get.get.return_value = [mock_document]
mock_worker_objects.return_value = mock_get
tasks._delete_worker('worker1')
mock_document.delete.assert_called_once()
示例7: test__delete_worker_no_database_entry
def test__delete_worker_no_database_entry(self):
"""
Call _delete_worker() with a Worker that is not in the database. _delete_worker() relies on
the database information, so it should return without error when called in this way.
"""
try:
tasks._delete_worker('does not exist Worker name')
except Exception:
self.fail('_delete_worker() on a Worker that is not in the database caused an '
'Exception')
示例8: shutdown
def shutdown(self, consumer):
"""
Called when the consumer is shut down.
So far, this just cleans up the database by removing the worker's record in
the workers collection.
:param consumer: The consumer instance
:type consumer: celery.worker.consumer.Consumer
"""
tasks._delete_worker(consumer.hostname, normal_shutdown=True)
示例9: test_cancels_all_found_task_status_objects
def test_cancels_all_found_task_status_objects(self):
mock_task_id_a = mock.Mock()
mock_task_id_b = mock.Mock()
self.mock_task_status_manager.find_by_criteria.return_value = [{'task_id': mock_task_id_a},
{'task_id': mock_task_id_b}]
tasks._delete_worker('worker1')
find_by_criteria = self.mock_task_status_manager.find_by_criteria
find_by_criteria.assert_called_once_with(self.mock_criteria.return_value)
self.mock_cancel.assert_has_calls([mock.call(mock_task_id_a), mock.call(mock_task_id_b)])
示例10: shutdown_worker
def shutdown_worker(signal, sender, **kwargs):
"""
Called when a worker is shutdown.
So far, this just cleans up the database by removing the worker's record in
the workers collection.
:param signal: The signal being sent to the worker
:type signal: int
:param instance: The hostname of the worker
:type instance: celery.apps.worker.Worker
:param kwargs: Other params (unused)
:type kwargs: dict
"""
tasks._delete_worker(sender.hostname, normal_shutdown=True)
示例11: initialize_worker
def initialize_worker(sender, instance, **kwargs):
"""
This function performs all the necessary initialization of the Celery worker.
We clean up old state in case this worker was previously running, but died unexpectedly.
In such cases, any Pulp tasks that were running or waiting on this worker will show incorrect
state. Any reserved_resource reservations associated with the previous worker will also be
removed along with the worker entry in the database itself. The working directory specified in
/etc/pulp/server.conf (/var/cache/pulp/<worker_name>) by default is removed and recreated. This
is called early in the worker start process, and later when it's fully online, pulp_celerybeat
will discover the worker as usual to allow new work to arrive at this worker. If there is no
previous work to cleanup, this method still runs, but has no effect on the database.
After cleaning up old state, it ensures the existence of the worker's working directory.
Lastly, this function makes the call to Pulp's initialization code.
It uses the celeryd_after_setup signal[0] so that it gets called by Celery after logging is
initialized, but before Celery starts to run tasks.
If the worker is a resource manager, it tries to acquire a lock stored within the database.
If the lock cannot be acquired immediately, it will wait until the currently active instance
becomes unavailable, at which point the worker cleanup routine will clear the lock for us to
acquire. While the worker remains in this waiting state, it is not connected to the broker and
will not attempt to do any work. A side effect of this is that, if terminated while in this
state, the process will not send the "worker-offline" signal used by the EventMonitor to
immediately clean up terminated workers. Therefore, we override the SIGTERM signal handler
while in this state so that cleanup is done properly.
[0] http://celery.readthedocs.org/en/latest/userguide/signals.html#celeryd-after-setup
:param sender: The hostname of the worker
:type sender: basestring
:param instance: The Worker instance to be initialized (unused)
:type instance: celery.apps.worker.Worker
:param kwargs: Other params (unused)
:type kwargs: dict
"""
initialization.initialize()
# Delete any potential old state
tasks._delete_worker(sender, normal_shutdown=True)
# Create a new working directory for worker that is starting now
common_utils.delete_worker_working_directory(sender)
common_utils.create_worker_working_directory(sender)
# If the worker is a resource manager, try to acquire the lock, or wait until it
# can be acquired
if sender.startswith(constants.RESOURCE_MANAGER_WORKER_NAME):
get_resource_manager_lock(sender)
示例12: test_criteria_is_used_in_filter_workers
def test_criteria_is_used_in_filter_workers(self):
tasks._delete_worker('worker1')
self.mock_resources.filter_workers.assert_called_once_with(self.mock_criteria.return_value)
示例13: test_removes_all_associated_reserved_resource_entries
def test_removes_all_associated_reserved_resource_entries(self):
tasks._delete_worker('worker1')
self.assertTrue(self.mock_reserved_resource.get_collection.called)
remove = self.mock_reserved_resource.get_collection.return_value.remove
remove.assert_called_once_with({'worker_name': 'worker1'})
示例14: test_removes_the_worker
def test_removes_the_worker(self):
mock_worker = mock.Mock()
self.mock_resources.filter_workers.return_value = tuple([mock_worker])
tasks._delete_worker('worker1')
mock_worker.delete.assert_called_once_with()
示例15: test_normal_shutdown_true_logs_correctly
def test_normal_shutdown_true_logs_correctly(self):
tasks._delete_worker('worker1', normal_shutdown=True)
self.assertTrue(not self.mock_gettext.called)
self.assertTrue(not self.mock_logger.error.called)