Last active
October 2, 2018 23:39
-
-
Save noriyukitakei/35bbc17d6aab38802c0f5bef6a8db1b7 to your computer and use it in GitHub Desktop.
クラウドデザインパターンを実践してみたシリーズ 〜 Scheduler Agent Supervisorパターン〜【retrieveResponseMessage】
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MySQLのモジュールを読み込む | |
const mysql = require('mysql2'); | |
// ファイルを読み込むためのモジュールを読み込む | |
const fs = require('fs'); | |
module.exports = function (context, myQueueItem) { | |
context.log('JavaScript queue trigger function processed work item:', myQueueItem); | |
// MySQLに接続するための情報を環境変数から取得する。 | |
var conn = mysql.createConnection( | |
{host: process.env['MYSQL_HOST'], | |
user: process.env['MYSQL_USER'], | |
password: process.env['MYSQL_SECRET'], | |
database: process.env['MYSQL_DB'], | |
port: 3306, | |
ssl:{ca:fs.readFileSync(process.env['MYSQL_CA'])} | |
}); | |
conn.query( | |
// キューから受け取ったJSONをもとに、テーブルt_state_storeのフィールドprocess_stateを更新します。 | |
// Queue Triggerで動く関数なので、キューの情報はmyQueueItemに入っています。 | |
'UPDATE `t_state_store` SET process_state = "' + myQueueItem.processState + '"' | |
+ ' where task_id = ' + myQueueItem.taskId, | |
function (error) { | |
if(error) throw err; | |
conn.end(); | |
}) | |
context.done(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment