Posted in Cloud, JavaScript

[Cloud] Kii Cloud – helpfull script Server Code

kii

Kii Cloud is one of powerful cloud for developer. It provides a helpful data storage solution. So, the developer donot need to care the way store data.

The Kii Cloud also provide one strong feature that is Server Code. When you create a new project on Kii cloud, a Server Code for that project is created. You can make your own Server Code then deploy it to your project. I worked with Server Code for some projects, I used it to create triggers, scheduler, etc.

For example: you can create a trigger for a certain record which is inserted into one bucket (table), then Server Code will call your trigger function to do something automatically.

For Server Code implementation, please refer this guide

I created some useful script (for Window system) to help working on Server Code more convenient. I hope it is helpful for person who work on Server Code of Kii Cloud.

The script for Window system has 3 main part:

Part 1: define configuration for Kii project:

set kiiDeveloperLogFodder=%cd%\Kii_Logger
set KiiLogFile=”D:\KiiLogFile.txt”
set ServerCodeFilePath=”D:\your_server_code_path\servercode.js”
set HookConfigFilePath=”D:\your_hookConfig_path\hookConfig\hookConfig.json”

echo %kiiDeveloperLogFodder%

del %KiiLogFile%

set APP_ID=your_app_id
set APP_KEY=your_app_key
set CLIENT_ID=your_client_id
set CLIENT_SECRET=your_client_secret

set KiiSite=jp
set dateFrom=2015-11-18
set dateTo=2018-11-18
set codeVersion=your_code_version
set userId=your_user_id

set expectedLogLinesNumber=1500

set appKeys=–site %KiiSite% –app-id %APP_ID% –app-key %APP_KEY% –client-id %CLIENT_ID% –client-secret %CLIENT_SECRET%
set fromDateToDate=–date-from %dateFrom% –date-to %dateTo%
set userIdCommand=–user-id %userId%
set expectedLogLinesCommand=–num %expectedLogLinesNumber%
set infoLevelCommand=–level INFO
set debugLevelCommand=–level DEBUG
set errorLevelCommand=–level ERROR

Part 2: define Option for each script

set option_1=”Get Kii log”
set option_2=”Deploy Server Code”
set option_3=”List the Available Versions”
set option_4=”Get your Server Code”
set option_5=”Get Server Hook Config File”
set option_6=”List Server Code Execution Results”
set option_7=”Get the Detailed Execution Result”
set option_8=”NA”
set option_9=”NA”

ECHO 1) %option_1%
ECHO 2) %option_2%
ECHO 3) %option_3%
ECHO 4) %option_4%
ECHO 5) %option_5%
ECHO 6) %option_6%
ECHO 7) %option_7%
ECHO 8) %option_8%
ECHO 9) %option_9%

ECHO.

CHOICE /C 123456789 /M “Enter your choice:”

:: Note – list ERRORLEVELS in decreasing order
IF ERRORLEVEL 9 GOTO option_9
IF ERRORLEVEL 8 GOTO option_8
IF ERRORLEVEL 7 GOTO option_7
IF ERRORLEVEL 6 GOTO option_6
IF ERRORLEVEL 5 GOTO option_5
IF ERRORLEVEL 4 GOTO option_4
IF ERRORLEVEL 3 GOTO option_3
IF ERRORLEVEL 2 GOTO option_2
IF ERRORLEVEL 1 GOTO option_1

Part 3: define script contents to run for options which are defined at Part 2

:option_1
ECHO %option_1%
rem Get Kii log
node bin/kii-logs.js -t %appKeys% > %KiiLogFile%
GOTO End

:option_2
ECHO %option_2%
rem Deploy Server Code ==> Make sure that you update 2 files: KiiServerCode/servercode.js & KiiHookConfig/hookConfig.json
node bin/kii-servercode.js deploy-file –file ../KiiServerCode/servercode.js %appKeys% –hook-config ../KiiHookConfig/hookConfig.json
GOTO End

Result:

kii_servercode_script_result

PS: You also find full of scripts from my Github at KiiCloudServerCodeScript (Remember read README file before running scripts)

Share this topic if it is helpful 🙂

 

Advertisements