supervisorctl无法杀死进程/supervisorctl无法kill celery进程

使用supervisorctl shutdown 无法杀死进程.

解决方法1.

stopasgroup=true 选项配置到 supervisord.conf 文件中。因为不仅要杀死父进程,还要杀死子进程。

原文参考: https://stackoverflow.com/questions/24297683/cant-kill-celery-processes-started-by-supervisor

You should configurate the stopasgroup=true option into supervisord.conf file. Because you just not only kill the parent process but also the child process.

解决方法2.

手动kill

ps -ef | grep celery | grep -v grep | awk '{print $2}' | xargs kill -9

一个supervisord示例
[program:celery]
directory=/home/wukt/project/xianxia_backend/tasks
command=/home/wukt/.virtualenvs/shendipython3.6/bin/celery worker -l INFO -A tasks.app  --loglevel info
stdout_logfile=/tmp/celery/celery.log
stderr_logfile=/tmp/celery/celery.log
stopasgroup=true
;autostart=true
;autorestart=true
;startsecs=1
;stopwaitsecs=600

django 添加数据库comment的两种方法

方式1

来自于stack overflow: https://stackoverflow.com/questions/39057829/generate-create-table-sql-with-comment-from-migrations

I am just looking for a method do such a thing in Django, but found Django didn’t and won’t have this feature:see: https://code.djangoproject.com/ticket/13867

So just use the following command to output SQL generated by Django.

python manage.py sqlmigrate app 0001 > app001.sql

And next, edit app001.sql add comment for SQL sentences as following:

CREATE TABLE `gateway_order` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT "Order id",
  `updated_datetime` datetime NOT NULL COMMENT "Latest update time of order",
  `created_datetime` datetime NOT NULL COMMENT "Created time of order",
  `product_name` varchar(255) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB AUTO_INCREMENT=34848 DEFAULT CHARSET=utf8;

Then import the SQL to your database.

mysql -h127.0.0.1 -uroot -p --database yourdb < app001.sql

and run

python manage.py migrate app --fake

to told Django, you’ve already create the SQL in database.

If a better method found, please told me.

方式2

修改源码, 设置verbosename为mysql的comment

文件位置为: /django/db/backends/base/schema.py

找到 def column_sql(self, model, field, include_default=False)::, 添加两行:

# .....
        elif field.unique:
        sql += " UNIQUE"
        # 添加下面两行
        # 新增comment
        if field.verbose_name:
            sql += " COMMENT '{}'" .format(field.verbose_name)
        # Optionally add the tablespace if it's an implicitly indexed column
        tablespace = field.db_tablespace or model._meta.db_tablespace

            # .....

python elasticseach quickStart

几个快速入门小例子, 支持中文分词和拼音搜索. elastic Search 版本为: 6.7, docker-compose 地址为: https://github.com/sazima/docker-compose/tree/master/elastic_search_pinyin

创建索引index, 指定字段中文分词器和pinyin.

es = Elasticsearch()

es.indices.create('blog', body={
        "settings": {
            "number_of_shards": 3,
            "number_of_replicas": 1,
            "analysis": {
                "analyzer": {
                    "default": {
                        "tokenizer": "ik_smart"
                    },
                    "pinyin_analyzer": {
                        "type": "custom",
                        "tokenizer": "my_pinyin",
                        "filter": ["word_delimiter"]
                    }
                },
                "tokenizer": {
                    "my_pinyin": {
                        "type": "pinyin",
                        "keep_first_letter": True,
                        "keep_separate_first_letter": True,
                        "keep_full_pinyin": True,
                        "keep_original": True,
                        "limit_first_letter_length": 16,
                        "lowercase": True
                    }
                }
            }
        }
    })

创建doc, 设置字段mapping

es.indices.put_mapping(index='blog', doc_type='article', body={
        "properties": {
            "title": {
                "type": "text",
                "analyzer": "ik_max_word",
                "copy_to": True,
                "fields": {
                    "pinyin": {
                        "type": "text",
                        "term_vector": "with_positions_offsets",
                        "analyzer": "pinyin_analyzer",
                        "boost": 10
                    }
                }
            },
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "copy_to": True,
                "fields": {
                    "pinyin": {
                        "type": "text",
                        "term_vector": "with_positions_offsets",
                        "analyzer": "pinyin_analyzer",
                        "boost": 10
                    }
                }
            },
            "author": {
                "type": "text",
                "analyzer": "ik_max_word",
                "copy_to": True,
                "fields": {
                    "pinyin": {
                        "type": "text",
                        "term_vector": "with_positions_offsets",
                        "analyzer": "pinyin_analyzer",
                        "boost": 10
                    }
                }
            },
            "keyword": {
                "type": "text",
                "analyzer": "ik_max_word",
                "fields": {
                    "pinyin": {
                        "type": "text",
                        "term_vector": "with_positions_offsets",
                        "analyzer": "pinyin_analyzer",
                        "boost": 10
                    }
                }
            }}})

文档增删查

   es.create('blog', 'article', '2', {
        'title': '这是一个标题',
        'content': '这里是内容'
    })
    es.get('blog', 'article', 1)
    es.search('blog', 'article', {
        "query": {
            "multi_match": {
                "type": "best_fields",
                "operator": "and",
                "query": "zheshi",
                "fields": ["title", 'title.pinyin']
            }
        }})