Skip to content

Instantly share code, notes, and snippets.

🥑
Living the dream

Todd Sharp recursivecodes

🥑
Living the dream
View GitHub Profile
View demo-function.js
const fdk=require('@fnproject/fdk');
fdk.handle(function(evt){
  console.log(JSON.stringify(evt)) 
  return {'message': 'Hello'}
})
View start-qa-workflow.yaml
name: start-qa
on:
schedule:
- cron: '45 11 * * 1-5'
View start-qa-workflow.yaml
env:
INSTANCE_NAME: demo-qa-env
jobs:
start-qa-job:
name: 'Start QA Job'
runs-on: ubuntu-latest
steps:
View start-qa-workflow.yaml
- name: 'Write Config & Key Files'
  run: |
    mkdir ~/.oci
    echo "[DEFAULT]" >> ~/.oci/config
    echo "user=${{secrets.OCI_USER_OCID}}" >> ~/.oci/config
    echo "fingerprint=${{secrets.OCI_FINGERPRINT}}" >> ~/.oci/config
    echo "pass_phrase=${{secrets.OCI_PASSPHRASE}}" >> ~/.oci/config
    echo "region=${{secrets.OCI_REGION}}" >> ~/.oci/config
    echo "tenancy=${{secrets.OCI_TENANCY_OCID}}" >> ~/.oci/config
    echo "key_file=~/.oci/key.pem" >> ~/.oci/config
View start-qa-workflow.yaml
- name: 'Check Running DB Instance'
  run: |
    echo "::set-env name=DB_STATE::$( \
        oci db autonomous-database get \
        --autonomous-database-id ${{ secrets.AUTONOMOUS_DB_OCID }} \
        --query "data.\"lifecycle-state\"" \
        --raw-output \
    )"
- name: 'Start DB'
  if: ${{env.DB_STATE == 'STOPPED'}}
View start-qa-workflow.yaml
- name: 'Check Running VM Instance'
  run: |
    echo "::set-env name=INSTANCE_OCID::$( \
     oci compute instance list \
     --lifecycle-state STOPPED \
     --compartment-id ${{secrets.VM_COMPARTMENT_OCID}} \
     --display-name ${{env.INSTANCE_NAME}} \
     --query "data [0].id" \
     --raw-output \
    )"
View stop-qa-workflow.yaml
- name: 'Check Running DB Instance'
  run: |
    echo "::set-env name=DB_STATE::$( \
        oci db autonomous-database get \
        --autonomous-database-id ${{ secrets.AUTONOMOUS_DB_OCID }} \
        --query "data.\"lifecycle-state\"" \
        --raw-output \
    )"
- name: 'Stop DB'
  if: ${{env.DB_STATE == 'AVAILABLE'}}
View Main.java
public static void main(String[] args) throws IOException {
    Logger logger = LoggerFactory.getLogger(Main.class);
    int port = Integer.parseInt( System.getProperty("port", "30000") );
    socketServer = new ServerSocket(port);
    logger.info("Listening on localhost:{}...", port);
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        logger.info("Server shutting down. Goodbye...");
        try {
            socketServer.close();
        }
View MessageHandler.java
public class MessageHandler implements Runnable {
    private final Socket clientSocket;
    private final SyslogParser parser = new SyslogParserBuilder().build();
    private final Logger logger = LoggerFactory.getLogger(Main.class);
    public MessageHandler(Socket clientSocket) {
        this.clientSocket = clientSocket;
    }
    public void run() {
        BufferedReader reader = null;
        try {
View syslog.json
{
"syslog.header.appName": "app_id=ocid1.fnapp.oc1.phx...,fn_id=ocid1.fnfunc.oc1.phx...",
"syslog.header.version": "1",
"syslog.header.hostName": "runner-00001700e5f9",
"syslog.header.facility": "1",
"syslog.header.msgId": "app_id=ocid1.fnapp.oc1.phx...,fn_id=ocid1.fnfunc.oc1.phx...",
"syslog.header.timestamp": "2020-06-15T14:46:35Z",
"syslog.message": "Error in function: ReferenceError: foo is not defined",
"syslog.header.pri": "11",
"syslog.header.procId": "8",
You can’t perform that action at this time.