Exemple #1
0
 def test_do_call_method_sql_transport_type(self):
     self.app.connection = Mock()
     conn = self.app.connection.return_value = Mock(name='Connection')
     conn.transport.driver_type = 'sql'
     i = inspect(app=self.app)
     with pytest.raises(i.Error):
         i.do_call_method(['ping'])
Exemple #2
0
def autoscale_gpu_node():
    autoscaling_client = boto3.client(
        'autoscaling',
        region_name=settings.AWS_AUTOSCALING_REGION,
        aws_access_key_id=settings.AWS_AUTOSCALING_ACCESS_KEY_ID,
        aws_secret_access_key=settings.AWS_AUTOSCALING_SECRET_ACCESS_KEY,
    )

    i = inspect()
    active_tasks_per_node = [a[1] for a in list(i.active().items())]
    scheduled_tasks_per_node = [a[1] for a in list(i.scheduled().items())]
    reserved_tasks_per_node = [a[1] for a in list(i.reserved().items())]

    tasks_per_node = active_tasks_per_node + scheduled_tasks_per_node + reserved_tasks_per_node
    tasks = reduce(lambda x, y: x + y, tasks_per_node)

    task_names = [task['name'] for task in tasks]

    scale_to = 0
    if run_submission.name in task_names:
        scale_to = 1

    print(f"Scaling to {str(scale_to)} GPU nodes.")

    print(
        autoscaling_client.set_desired_capacity(
            AutoScalingGroupName='terraform-eks-eyra-prod01-gpu',
            DesiredCapacity=scale_to))
Exemple #3
0
 def test_do_call_method_sql_transport_type(self):
     self.app.connection = Mock()
     conn = self.app.connection.return_value = Mock(name='Connection')
     conn.transport.driver_type = 'sql'
     i = inspect(app=self.app)
     with pytest.raises(i.Error):
         i.do_call_method(['ping'])
Exemple #4
0
    def test_run(self, real):
        out = WhateverIO()
        i = inspect(app=self.app, stdout=out)
        with pytest.raises(Error):
            i.run()
        with pytest.raises(Error):
            i.run('help')
        with pytest.raises(Error):
            i.run('xyzzybaz')

        i.run('ping')
        real.assert_called()
        i.run('ping', destination='foo,bar')
        assert real.call_args[1]['destination'], ['foo' == 'bar']
        assert real.call_args[1]['timeout'] == 0.2
        callback = real.call_args[1]['callback']

        callback({'foo': {'ok': 'pong'}})
        assert 'OK' in out.getvalue()

        with patch('celery.bin.control.dumps') as dumps:
            i.run('ping', json=True)
            dumps.assert_called()

        instance = real.return_value = Mock()
        instance._request.return_value = None
        with pytest.raises(Error):
            i.run('ping')

        out.seek(0)
        out.truncate()
        i.quiet = True
        i.say_chat('<-', 'hello')
        assert not out.getvalue()
Exemple #5
0
    def test_run(self, real):
        out = WhateverIO()
        i = inspect(app=self.app, stdout=out)
        with pytest.raises(Error):
            i.run()
        with pytest.raises(Error):
            i.run('help')
        with pytest.raises(Error):
            i.run('xyzzybaz')

        i.run('ping')
        real.assert_called()
        i.run('ping', destination='foo,bar')
        assert real.call_args[1]['destination'], ['foo' == 'bar']
        assert real.call_args[1]['timeout'] == 0.2
        callback = real.call_args[1]['callback']

        callback({'foo': {'ok': 'pong'}})
        assert 'OK' in out.getvalue()

        with patch('celery.bin.control.dumps') as dumps:
            i.run('ping', json=True)
            dumps.assert_called()

        instance = real.return_value = Mock()
        instance._request.return_value = None
        with pytest.raises(Error):
            i.run('ping')

        out.seek(0)
        out.truncate()
        i.quiet = True
        i.say_chat('<-', 'hello')
        assert not out.getvalue()
Exemple #6
0
 def test_command_info(self):
     i = inspect(app=self.app)
     assert i.get_command_info(
         'ping',
         help=True,
         color=i.colored.red,
         app=self.app,
     )
Exemple #7
0
 def queue(self, request, *args, **kwargs):
     try:
         inspect_task = inspect(app=celery_app)
         replies = inspect_task.run('active_queues')
         res = [{
             'name': key,
             'queue': [item['name'] for item in replies[key]]
         } for key in replies.keys()]
         return Response(msg(data=res))
     except Exception as e:
         return Response(msg(err=str(e)))
Exemple #8
0
def queue_count():
    """Count tasks in celery."""
    inspector = inspect()
    task_count = 0
    reserved = inspector.reserved()
    if reserved:
        for key, values in reserved.items():
            task_count += len(values)
    active = inspector.active()
    if active:
        task_count = sum(active.values())
    return task_count
Exemple #9
0
def has_any_tasks():
    excluded = ['check_if_idle', 'auto_sync']

    inspector = inspect(celery.app)
    active = inspector.call(method='active', arguments={})
    scheduled = inspector.call(method='scheduled', arguments={})
    reserved = inspector.call(method='reserved', arguments={})
    count = (
        count_tasks(active, excluded)
        + count_tasks(scheduled, excluded)
        + count_tasks(reserved, excluded)
    )
    return not not count
Exemple #10
0
    def test_say_directions(self):
        i = inspect(self.app)
        i.out = Mock()
        i.quiet = True
        i.say_chat('<-', 'hello out')
        i.out.assert_not_called()

        i.say_chat('->', 'hello in')
        i.out.assert_called()

        i.quiet = False
        i.out.reset_mock()
        i.say_chat('<-', 'hello out', 'body')
        i.out.assert_called()
Exemple #11
0
    def test_say_directions(self):
        i = inspect(self.app)
        i.out = Mock()
        i.quiet = True
        i.say_chat('<-', 'hello out')
        i.out.assert_not_called()

        i.say_chat('->', 'hello in')
        i.out.assert_called()

        i.quiet = False
        i.out.reset_mock()
        i.say_chat('<-', 'hello out', 'body')
        i.out.assert_called()
Exemple #12
0
def check_if_idle():
    excluded = ['check_if_idle']

    inspector = inspect(celery.app)
    active = inspector.call(method='active', arguments={})
    scheduled = inspector.call(method='scheduled', arguments={})
    reserved = inspector.call(method='reserved', arguments={})
    count = count_tasks(active, excluded) + count_tasks(scheduled, excluded) + \
        count_tasks(reserved, excluded)
    if not count:
        db_tasks = Task.objects.exclude(status=Task.STATUS_BROKEN).\
            exclude(status=Task.STATUS_SUCCESS).count()
        if db_tasks:
            print('Dispatching remaining %d tasks.' % db_tasks)
            dispatch_pending_tasks()
            from snoop.data.dispatcher import dispatch_walk_tasks
            dispatch_walk_tasks()
Exemple #13
0
 def test_command_info(self):
     i = inspect(app=self.app)
     assert i.get_command_info(
         'ping', help=True, color=i.colored.red, app=self.app,
     )
Exemple #14
0
 def test_epilog(self):
     assert inspect(app=self.app).epilog
Exemple #15
0
 def test_list_commands_color(self):
     i = inspect(app=self.app)
     assert i.list_commands(help=True, color=i.colored.red, app=self.app)
     assert i.list_commands(help=False, color=None, app=self.app)
Exemple #16
0
 def test_list_commands_color(self):
     i = inspect(app=self.app)
     assert i.list_commands(help=True, color=i.colored.red, app=self.app)
     assert i.list_commands(help=False, color=None, app=self.app)
Exemple #17
0
 def test_usage(self):
     assert inspect(app=self.app).usage('foo')
Exemple #18
0
 def test_usage(self):
     assert inspect(app=self.app).usage('foo')
Exemple #19
0
 def test_epilog(self):
     assert inspect(app=self.app).epilog