From bcec40edc9b250c4287354abdffc6ccbfe1950d9 Mon Sep 17 00:00:00 2001 From: "Maxim [maxirmx] Samsonov" Date: Fri, 13 Dec 2024 00:15:45 +0300 Subject: [PATCH 1/3] feat: create async gem sample --- .github/workflows/macos.yml | 35 +++++++++++++++++++++++++++++++++++ async/Gemfile | 7 +++++++ async/binance.rb | 21 +++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 async/Gemfile create mode 100755 async/binance.rb diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index b1fc371..54f15d8 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -11,6 +11,41 @@ concurrency: cancel-in-progress: true jobs: + test-async: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ macos-13, macos-14 ] + steps: + - name: Select XCode + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: 15.0.1 + + - name: Brew install + run: | + brew install bison flex binutils libffi double-conversion boost jemalloc fmt glog gnu-sed bash zlib ncurses + echo "$(brew --prefix bison)/bin" >> $GITHUB_PATH + + - name: Install gem + run: gem install tebako + + - name: Checkout sample + uses: actions/checkout@v4 + + - name: Package + run: tebako press -e binance.rb -o binance.tebako -r binance + + - name: Start packaged application + run: ./async.tebako & + + - name: Wait for app to start and do some work + run: sleep 10 + + - name: End application + run: pkill -f async.tebako + test-sinatra: runs-on: ${{ matrix.os }} strategy: diff --git a/async/Gemfile b/async/Gemfile new file mode 100644 index 0000000..9a0e459 --- /dev/null +++ b/async/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "async" +gem "async-http" +gem "async-websocket" diff --git a/async/binance.rb b/async/binance.rb new file mode 100755 index 0000000..498ac9c --- /dev/null +++ b/async/binance.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2021-2024, by Samuel Williams. + +require "async" +require "async/http" +require "async/websocket" + +URL = "wss://stream.binance.com:9443/ws/btcusdt@bookTicker" + +Async do |task| + endpoint = Async::HTTP::Endpoint.parse(URL, alpn_protocols: Async::HTTP::Protocol::HTTP11.names) + + Async::WebSocket::Client.connect(endpoint) do |connection| + while message = connection.read + $stdout.puts message.parse + end + end +end From 7d32b212271c15dbc488f6665cdbd6b4d53f38cf Mon Sep 17 00:00:00 2001 From: "Maxim [maxirmx] Samsonov" Date: Fri, 13 Dec 2024 00:46:14 +0300 Subject: [PATCH 2/3] feat: create async gem sample [2] --- .github/workflows/macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 54f15d8..e88ad60 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v4 - name: Package - run: tebako press -e binance.rb -o binance.tebako -r binance + run: tebako press -e binance.rb -o binance.tebako -r async - name: Start packaged application run: ./async.tebako & From 1a002d26bcca6aaf040ff59c2c658bc72ec644b2 Mon Sep 17 00:00:00 2001 From: "Maxim [maxirmx] Samsonov" Date: Fri, 13 Dec 2024 00:50:03 +0300 Subject: [PATCH 3/3] feat: create async gem sample [3] --- .github/workflows/docker.yml | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0d3696f..854d259 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,6 +11,43 @@ concurrency: cancel-in-progress: true jobs: + test-async: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + container: + - 'ubuntu-20.04' + - 'alpine-3.17' + package_ruby_ver: + - '3.2.5' + container: + image: ghcr.io/tamatebako/tebako-${{ matrix.container }}:latest + steps: + - name: Install curl/procps + run: | + if [ -e "/etc/lsb-release" ]; then + apt-get -y update + apt-get -y install curl procps + elif [ -e "/etc/alpine-release" ]; then + apk --no-cache --upgrade add curl procps + fi + + - name: Checkout sample + uses: actions/checkout@v4 + + - name: Package + run: tebako press -e binance.rb -o binance.tebako -r async -R ${{ matrix.package_ruby_ver }} + + - name: Start packaged application + run: ./binance.tebako & + + - name: Wait for the application to start and do some work + run: sleep 10 + + - name: End application + run: pkill -f binance.tebako + test-sinatra: runs-on: ubuntu-latest strategy: