Python: ジョブキューイング

タスクキューシステム Full Stack Python Celery https://docs.celeryq.dev/en/stable/ PYPI: celery redis django-celery-results django-redis Redis: Using Redis poetry add "celery[redis]" djang-celery-results: django-celery-results - Using the Django ORM/Cache as a result backend poetry add django-celery-results Periodic Task: Periodic Tasks 記事: 【Django】CeleryとRedisで非同期処理を実装する方法 DjangoとCeleryを使った非同期処理の結果取得までの流れ 【Python x Django】Djangoによる非同期処理実装(Cerery,Redis) Deploying Django on AWS: Setting up Celery and SQS Celery Task Queue with AWS SQS MySQL:Database returned an invalid datetime value. Are time zone definitions for your database installed? macOS: ...

2023年4月7日 · 1 分

MySQL: ERROR 3780 (HY000) at line 1406622: Referencing column 'os_branch_id' and referenced column 'id' in foreign key constraint '***' are incompatible.

ERROR 3780 (HY000) at line 1406622: Referencing column 'os_branch_id' and referenced column 'id' in foreign key constraint '***' are incompatible. 1 2 3 4 5 6 7 8 9 10 11 CREATE TABLE `gas_bombehouse` ( `id` int NOT NULL AUTO_INCREMENT, `code` varchar(50) NOT NULL, .... `os_branch_id` bigint DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`), KEY `gas_bombehouse_os_branch_id_d35d17d3_fk_outsource` (`os_branch_id`), CONSTRAINT `gas_bombehouse_os_branch_id_d35d17d3_fk` FOREIGN KEY (`os_branch_id`) REFERENCES `outsources_outsourcebranch` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb3; /*!40101 SET character_set_client = @saved_cs_client */; 1 2 3 4 5 6 7 CREATE TABLE `outsources_outsourcebranch` ( `id` bigint NOT NULL AUTO_INCREMENT, ... PRIMARY KEY (`id`), ) ENGINE=InnoDB AUTO_INCREMENT=9751 DEFAULT CHARSET=utf8mb3; /*!40101 SET character_set_client = @saved_cs_client */; 原因 リモートの mysqldump を ローカルにそのまま取り込もうとしていた 古いスキーマが残っていて、そのidがint であったため。 DROP TABLE IF EXISTS table CREATE TABLE table が実行されるまで、古いスキーマが残っている、ということ。 1 2 3 4 5 DROP TABLE IF EXISTS `outsources_outsourcebranch`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `outsources_outsourcebranch` .... 解決 DROP DATABASE & CREATE DATABASE して、更地にmysqldumpをロードする 資料 How to fix MySQL error 1215 Cannot add foreign key constraint ...

2023年4月6日 · 2 分

PYPI

cryptgraphy/cffi M1 Mac に cryptgraphy ( cffi ) をインストールする

2023年4月6日 · 1 分

Django: model から DRF ModelSerializer を参照する

modelクラスからシリアライザクラスを参照する models <- api の照合依存のレイアウト 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 partners ├── __init__.py ├── api │ ├── __init__.py │ ├── filters.py │ ├── permissions.py │ ├── schema.py │ ├── serializers.py │ ├── urls.py │ └── viewsets.py ├── apps.py ├── models │ ├── __init__.py │ ├── apimodels.py │ ├── defs.py │ ├── managers.py │ ├── methods.py │ ├── models.py │ └── querysets.py ├── tasks.py └── views.py

2023年4月5日 · 1 分

Python: ThreadPoolExecutor: マルチスレッド

Python: ThreadPoolExecutor: マルチスレッド 1 2 3 4 5 6 7 8 9 def bind_all(self): def _bind(instance): instance.bind_to_debt() executor = ThreadPoolExecutor(max_workers=4) for i in self.all(): executor.submit(_bind, i) executor.shutdown() # 全てのスレッドが終わるのを待つ

2023年3月30日 · 1 分

MySQL: JSON_OBJECT: JSON文字列フィールドを含む時のバックスラッシュ問題

how to replace double back slash character to single one from MySQL JSON_OBJECT function results for column including JSON string You can use the MySQL function REPLACE() to replace double backslashes with single backslashes in a JSON object. Here’s an example: 1 SELECT REPLACE(JSON_OBJECT(column_name), '\\\\\\\\', '\\\\') FROM table_name; This will return the column values with double backslashes replaced with single backslashes. If you want to insert a JSON object literal with single backslashes instead of double backslashes, you can set the NO_BACKSLASH_ESCAPES SQL mode⁴. When this mode is set, a single backslash instead of double backslashes can be used to insert the JSON object literal, and the backslashes are preserved⁴. If you use the JSON_OBJECT() function when performing the insert and this mode is set, you must alternate single and double quotes⁴. ...

2023年3月28日 · 2 分

Django:OpenAPI(Swagger) Scheme を出力して Pydatic クラスを生成できるようにする

DRF: コマンドでShemaを生成する 1 pip install datamodel-code-generator ProfileSerializer(ModelSerializer)から Pydanticモデルを生成する 1 python manage.py generateschema --format openapi-json | jq ".components.schemas.Profile" | datamodel-codegen --output /tmp/model.py

2023年3月24日 · 1 分

Google Spreadsheet を TSVファイルに落とす

gsheet.py Googleスプレッドシートのダウンロード メインオプション Usage: gsheet.py [OPTIONS] COMMAND [ARGS]... Tools Subcommand Options: -s, --secret_file TEXT クレデンシャルJSONファイル -o, --out TEXT --help Show this message and exit. Commands: extract URLのシートは クレデンシャルJSONの client_email に対して共有設定すること extract サブコマンド: Usage: gsheet.py extract [OPTIONS] URL URLのシートは クレデンシャルJSONの client_email に対して共有設定すること Options: -n, --sheet_name TEXT --help Show this message and exit. インストール 1 pip install click gspread google-auth-httplib2 oauth2client クレデンシャルJSONの作り方: https://note.com/kohaku935/n/ned9e907aac77 GCPでプロジェクト作成 (https://console.cloud.google.com/) APIとサービス > ライブラリ から Google Drive API を有効 APIとサービス > ライブラリ から Google Sheets AP Iを有効 APIとサービス > 認証情報 > 認証情報を作成 でサービスアカウント を作成 サービスアカウント に 編集者 ロールを設定 APIとサービス > 認証情報 > 作成した サービスアカウント を選択し、キー の生成 キー画面で、鍵を追加 。 新しい鍵を作成 で作成。 タイプにJSONを選択。 ダウンロードされたJSONを適切な場所に保存

2023年3月18日 · 1 分

Snowfake: ビュー

Snowflake View ビューの概要 CREATE VIEW マテリアライズドビュー(Enterprise Edition) マテリアライズドビューの使用 ベーステーブルで実行された DML の量に関係なく、マテリアライズドビューを介してアクセスされるデータは常に最新です。 マテリアライズドビューが最新になる前にクエリが実行されると、Snowflakeはマテリアライズドビューを更新するか、 マテリアライズドビューの最新部分を使用して、必要な新しいデータをベーステーブルから取得します。 CREATE MATERIALIZED VIEW ビューとマテリアライズド・ビューの違いを理解する Snowflake マテリアライズドビューについて SnowflakeのMaterialized View マテリアライズドビューとそのベーステーブルをクラスタリングするためのベストプラクティス PostgreSQL マテリアライズドビューの機能(PostgreSQL) マテリアライズドビューの内容をテーブルの最新の状態と同じにしたいときには、REFRESH MATERIALIZED VIEWを実行します MySQL MySQLでMaterialized Viewを実現する 残念ながら、MySQLではデフォルトでMaterialized Viewを作る機能は存在しません。 トリガーかバッチで参照用のテーブルを作る

2023年3月18日 · 1 分

Snowfale : MySQL 移行データ比較

MySQL -> Snowflake データ移行後の比較 対象フィールド型(Python) 集計 MySQL Snowflake 補足 Decimal 単純合計 SUM(field) SUM(field) float 単純合計 SUM(field) SUM(field) int 単純合計 SUM(field) SUM(field) str MD5の合計 SUM(CONV(SUBSTRING(MD5(field)), 1, 8), 16, 10) SUM(TO_NUMBER(SUBSTR(MD5(field), 1, 8), ‘XXXXXXXX’)) MySQLの整数が小さいので先頭8バイトだけ datetime Unixエポック合計 SUM(UNIX_TIMESTAMP(field)) SUM(ZEROIFNULL(DATE_PART(EPOCH_SECOND, field)) - 32400) Snowflakeはローカルタイムゾーン date Unixエポック合計 SUM(UNIX_TIMESTAMP(field)) SUM(ZEROIFNULL(DATE_PART(EPOCH_SECOND, field)) - 32400) Snowflakeはローカルタイムゾーン time 秒数の合計 SUM(TIME_TO_SEC(field)) SUM(TIMEDIFF(SECOND, ‘00:00:00’::TIME, field::TIME))

2023年3月17日 · 1 分