From 8207e5015afd73e6f69f16d73db3db8c160f4463 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Mon, 19 Dec 2022 10:43:20 -0500 Subject: [PATCH 01/12] Lamby v4 Interface --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3c821e6..6d5d6ba 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,11 @@ LambdaPunch.push do end ``` -For example, if you are using Rails with AWS Lambda via the [Lamby](https://lamby.custominktech.com/) gem along with [New Relic APM](https://dev.to/aws-heroes/using-new-relic-apm-with-rails-on-aws-lambda-51gi) here is how your handler function might appear to ensure their metrics are flushed after each request. +For example, if you are using Rails with AWS Lambda via the [Lamby](https://lamby.custominktech.com/) v4 (or higher) gem along with [New Relic APM](https://dev.to/aws-heroes/using-new-relic-apm-with-rails-on-aws-lambda-51gi) here is how you configure the handled proc called after `Lamby.cmd` in an `ensure` block. This will force metrics to be flushed after each request. ```ruby -def handler(event:, context:) - Lamby.handler $app, event, context -ensure +# config/environments/production.rb +config.lambda.handled_proc = Proc.new do |_event, context| LambdaPunch.push { NewRelic::Agent.agent.flush_pipe_data } LambdaPunch.handled!(context) end From 673df26b6ff9bfdf99e28773aeb6f87fbdbeb8a4 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Tue, 20 Dec 2022 13:50:34 -0500 Subject: [PATCH 02/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d5d6ba..311f553 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # 👊 LambdaPunch -Lamby: Simple Rails & AWS Lambda Integration using Rack.Asynchronous background job processing for AWS Lambda with Ruby using [Lambda Extensions](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html). Inspired by the [SuckerPunch](https://github.com/brandonhilkert/sucker_punch) gem but specifically tooled to work with Lambda's invoke model. +Lamby: Simple Rails & AWS Lambda Integration using Rack.Asynchronous background job processing for AWS Lambda with Ruby using [Lambda Extensions](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html). Inspired by the [SuckerPunch](https://github.com/brandonhilkert/sucker_punch) gem but specifically tooled to work with Lambda's invoke model. **For a more robust background job solution, please consider using AWS SQS with the [Lambdakiq](https://github.com/customink/lambdakiq) gem. A drop-in replacement for [Sidekiq](https://github.com/mperham/sidekiq) when running Rails in AWS Lambda using the [Lamby](https://lamby.custominktech.com/) gem.** From 1fc507ffedd393a6af76b6919a94cd3a66430de9 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sun, 16 Apr 2023 12:10:14 -0400 Subject: [PATCH 03/12] Basic Exe Install Interface. --- CHANGELOG.md | 8 +++++++- README.md | 39 +++++++++++++++++++------------------ exe/lambda_punch | 10 ++++++++++ lib/lambda_punch/version.rb | 2 +- 4 files changed, 38 insertions(+), 21 deletions(-) create mode 100755 exe/lambda_punch diff --git a/CHANGELOG.md b/CHANGELOG.md index f3f99e0..32a3a37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,14 @@ +## [1.1.0] - 2023-04-16 + +### Added + +- New `lambda_punch` install interface. + ## [1.0.3] - 2021-10-27 ### Added -- +- Any Timeout Gem. Tempfile Location Interface ### Changed diff --git a/README.md b/README.md index 311f553..06f7a4d 100644 --- a/README.md +++ b/README.md @@ -18,35 +18,36 @@ The LambdaPunch extension process is very small and lean. It only requires a few ## 🎁 Installation -Add this line to your project's `Gemfile` and then make sure to `bundle install` afterward. +Add this line to your project's `Gemfile` and then make sure to `bundle install` afterward. It is only needed in the `production` group. ```ruby gem 'lambda_punch' ``` -Now, within your application's handler file, make sure to start the LambdaPunch DRb server outside of your handler method. Within the handler method, add an `ensure` section that lets the extension process know the request is done. +Within your project or [Rails application's](https://lamby.custominktech.com/docs/anatomy) `Dockerfile`, add the following. Make sure you do this before you `COPY` your code. The idea is to implicitly use the default `USER root` since it needs permissions to create an `/opt/extensions` directory. -```ruby -LambdaPunch.start_server! - -def handler(event:, context:) - # ... -ensure - LambdaPunch.handled!(context) -end +```dockerfile +RUN gem install lambda_punch && lambda_punch install ``` -Within your project or [Rails application's](https://lamby.custominktech.com/docs/anatomy) `Dockerfile`, after you copy your code, add this `RUN` command to install the extension within your container's `/opt/extensions` directory. +Installation with AWS Lambda via the [Lamby](https://lamby.custominktech.com/) v4 (or higher) gem can be done using Lamby's `handled_proc` config. For example, appends these to your `config/environments/production.rb` file. Here we are ensuring that the LambdaPunch DRb server is running and that after each Lamby request we notify LambdaPunch. -```dockerfile -RUN bundle exec rake lambda_punch:install +```ruby +config.to_prepare { LambdaPunch.start_server! } +config.lamby.handled_proc = Proc.new do |_event, context| + LambdaPunch.handled!(context) +end ``` -If you are using `LambdaPunch` with a non-Rails project, add this to your Rake file +If you are using an older version of Lamby or a simple Ruby project with your own handler method, the installation would look something like this: ```ruby -spec = Gem::Specification.find_by_name 'lambda_punch' -load "#{spec.gem_dir}/lib/lambda_punch/tasks/install.rake" +LambdaPunch.start_server! +def handler(event:, context:) + # ... +ensure + LambdaPunch.handled!(context) +end ``` ## 🧰 Usage @@ -59,11 +60,11 @@ LambdaPunch.push do end ``` -For example, if you are using Rails with AWS Lambda via the [Lamby](https://lamby.custominktech.com/) v4 (or higher) gem along with [New Relic APM](https://dev.to/aws-heroes/using-new-relic-apm-with-rails-on-aws-lambda-51gi) here is how you configure the handled proc called after `Lamby.cmd` in an `ensure` block. This will force metrics to be flushed after each request. +A common use case would be to ensure the [New Relic APM](https://dev.to/aws-heroes/using-new-relic-apm-with-rails-on-aws-lambda-51gi) flushes its data after each request. Using Lamby in your `config/environments/production.rb` file would look like this: ```ruby -# config/environments/production.rb -config.lambda.handled_proc = Proc.new do |_event, context| +config.to_prepare { LambdaPunch.start_server! } +config.lamby.handled_proc = Proc.new do |_event, context| LambdaPunch.push { NewRelic::Agent.agent.flush_pipe_data } LambdaPunch.handled!(context) end diff --git a/exe/lambda_punch b/exe/lambda_punch new file mode 100755 index 0000000..3f247a4 --- /dev/null +++ b/exe/lambda_punch @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +require 'rubygems' +require 'rake' + +load "#{spec.gem_dir}/lib/lambda_punch/tasks/install.rake" + +command = ARGV[0] || 'install' + +Rake::Task["lambda_punch:#{command}"].invoke diff --git a/lib/lambda_punch/version.rb b/lib/lambda_punch/version.rb index 93259dd..5e7e341 100644 --- a/lib/lambda_punch/version.rb +++ b/lib/lambda_punch/version.rb @@ -1,3 +1,3 @@ module LambdaPunch - VERSION = "1.0.3" + VERSION = "1.1.0" end From b505a0ed43353bcbb94496e9153e8885def7296e Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sun, 16 Apr 2023 19:59:36 +0000 Subject: [PATCH 04/12] Fix installer. Devcontainer. --- .devcontainer/Dockerfile | 1 + .devcontainer/devcontainer.json | 19 +++++++++++++++++++ .devcontainer/postCreate.sh | 6 ++++++ .github/workflows/test.yml | 21 ++++++++++----------- CHANGELOG.md | 6 ++++++ Dockerfile | 2 -- Gemfile.lock | 12 ++++++++---- bin/_setup | 6 ------ bin/_test | 4 ---- bin/bootstrap | 6 ------ bin/run | 6 ------ bin/setup | 6 +++--- bin/test | 4 +--- docker-compose.yml | 10 ---------- exe/lambda_punch | 1 + lib/lambda_punch/version.rb | 2 +- test/cases/rake_test.rb | 7 ++++++- 17 files changed, 62 insertions(+), 57 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/postCreate.sh delete mode 100644 Dockerfile delete mode 100755 bin/_setup delete mode 100755 bin/_test delete mode 100755 bin/bootstrap delete mode 100755 bin/run delete mode 100644 docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..ef3eb44 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1 @@ +FROM mcr.microsoft.com/devcontainers/ruby:3.1 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..6777398 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,19 @@ +{ + "name": "lambda_punch", + "build": { + "dockerfile": "Dockerfile" + }, + "features": { + "ghcr.io/devcontainers/features/sshd:latest": {} + }, + "customizations": { + "vscode": { + "settings": { + "editor.formatOnSave": true + }, + "extensions": [] + } + }, + "postCreateCommand": ".devcontainer/postCreate.sh", + "remoteUser": "vscode" +} diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh new file mode 100755 index 0000000..87a845d --- /dev/null +++ b/.devcontainer/postCreate.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -e + +sudo rm -rf /opt +sudo mkdir /opt +sudo chown -R $USER /opt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c4d81b..06b765a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,16 +2,15 @@ name: Test on: [push] jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Checkout - uses: actions/checkout@v2 - - name: Bootstrap - run: | - ./bin/bootstrap - - name: Setup - run: | - ./bin/setup - - name: Test - run: | - ./bin/test + uses: actions/checkout@v3 + - name: Setup & Test + uses: devcontainers/ci@v0.3 + with: + env: | + CI + runCmd: | + ./bin/setup + ./bin/test diff --git a/CHANGELOG.md b/CHANGELOG.md index 32a3a37..6c652b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [1.1.1] - 2023-04-16 + +### Fixed + +- The `lambda_punch` install file. + ## [1.1.0] - 2023-04-16 ### Added diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 3728be8..0000000 --- a/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM public.ecr.aws/sam/build-ruby2.7 -WORKDIR /var/task diff --git a/Gemfile.lock b/Gemfile.lock index 7fd14b3..37a926f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - lambda_punch (1.0.3) + lambda_punch (1.1.1) concurrent-ruby rake rb-inotify @@ -74,7 +74,7 @@ GEM concurrent-ruby (1.1.9) crass (1.0.6) erubi (1.10.0) - ffi (1.15.4) + ffi (1.15.5) globalid (0.5.2) activesupport (>= 5.0) i18n (1.8.10) @@ -87,11 +87,13 @@ GEM marcel (1.0.2) method_source (1.0.0) mini_mime (1.1.2) + mini_portile2 (2.6.1) minitest (5.14.4) minitest-focus (1.3.1) minitest (>= 4, < 6) nio4r (2.5.8) - nokogiri (1.12.5-x86_64-linux) + nokogiri (1.12.5) + mini_portile2 (~> 2.6.1) racc (~> 1.4) pry (0.14.1) coderay (~> 1.1) @@ -137,7 +139,7 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) thor (1.1.0) - timeout (0.2.0) + timeout (0.3.2) tzinfo (2.0.4) concurrent-ruby (~> 1.0) websocket-driver (0.7.5) @@ -146,6 +148,8 @@ GEM zeitwerk (2.5.1) PLATFORMS + aarch64-linux + arm64-darwin-22 x86_64-linux DEPENDENCIES diff --git a/bin/_setup b/bin/_setup deleted file mode 100755 index d37a278..0000000 --- a/bin/_setup +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -set -e - -echo '== Installing dependencies ==' -bundle config set --local path 'vendor/bundle' -bundle install diff --git a/bin/_test b/bin/_test deleted file mode 100755 index b49cfc6..0000000 --- a/bin/_test +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -e - -bundle exec rake test diff --git a/bin/bootstrap b/bin/bootstrap deleted file mode 100755 index 61de921..0000000 --- a/bin/bootstrap +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -set -e - -echo '== Building containers ==' -docker pull public.ecr.aws/sam/build-ruby2.7 -docker-compose build diff --git a/bin/run b/bin/run deleted file mode 100755 index 7668776..0000000 --- a/bin/run +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -set -e - -docker-compose run \ - lambdapunch \ - $@ diff --git a/bin/setup b/bin/setup index 783451f..d37a278 100755 --- a/bin/setup +++ b/bin/setup @@ -1,6 +1,6 @@ #!/bin/sh set -e -docker-compose run \ - lambdapunch \ - ./bin/_setup +echo '== Installing dependencies ==' +bundle config set --local path 'vendor/bundle' +bundle install diff --git a/bin/test b/bin/test index f168a5d..b49cfc6 100755 --- a/bin/test +++ b/bin/test @@ -1,6 +1,4 @@ #!/bin/sh set -e -docker-compose run \ - lambdapunch \ - ./bin/_test +bundle exec rake test diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index a9dc578..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: '3.7' -services: - lambdapunch: - build: - context: . - dockerfile: Dockerfile - environment: - - CI=${CI} - volumes: - - ${PWD}:/var/task:delegated diff --git a/exe/lambda_punch b/exe/lambda_punch index 3f247a4..3612d21 100755 --- a/exe/lambda_punch +++ b/exe/lambda_punch @@ -3,6 +3,7 @@ require 'rubygems' require 'rake' +spec = Gem::Specification.find_by_name 'lambda_punch' load "#{spec.gem_dir}/lib/lambda_punch/tasks/install.rake" command = ARGV[0] || 'install' diff --git a/lib/lambda_punch/version.rb b/lib/lambda_punch/version.rb index 5e7e341..f45eb76 100644 --- a/lib/lambda_punch/version.rb +++ b/lib/lambda_punch/version.rb @@ -1,3 +1,3 @@ module LambdaPunch - VERSION = "1.1.0" + VERSION = "1.1.1" end diff --git a/test/cases/rake_test.rb b/test/cases/rake_test.rb index 92ec831..a637992 100644 --- a/test/cases/rake_test.rb +++ b/test/cases/rake_test.rb @@ -2,7 +2,6 @@ load 'lambda_punch/tasks/install.rake' class RakeTest < LambdaPunchSpec - before do FileUtils.rm_rf '/opt/extensions' end @@ -13,4 +12,10 @@ class RakeTest < LambdaPunchSpec assert File.exist?('/opt/extensions/lambdapunch') end + it 'has an exec installer' do + root = File.expand_path(File.join __FILE__, '..', '..', '..') + exe = "#{root}/exe/lambda_punch" + `#{exe} install` + assert File.exist?('/opt/extensions/lambdapunch') + end end From 64e20d6e73dc41f15bea40293d1be7e9207303c5 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sun, 16 Apr 2023 16:24:36 -0400 Subject: [PATCH 05/12] Fix dos on LAMBDA_TASK_ROOT --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06f7a4d..67162fb 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,18 @@ Add this line to your project's `Gemfile` and then make sure to `bundle install` gem 'lambda_punch' ``` -Within your project or [Rails application's](https://lamby.custominktech.com/docs/anatomy) `Dockerfile`, add the following. Make sure you do this before you `COPY` your code. The idea is to implicitly use the default `USER root` since it needs permissions to create an `/opt/extensions` directory. +Within your project or [Rails application's](https://lamby.custominktech.com/docs/anatomy) `Dockerfile`, add the following. Make sure you do this before you `COPY` your code. The idea is to implicitly use the default `USER root` since it needs permission to create an `/opt/extensions` directory. ```dockerfile RUN gem install lambda_punch && lambda_punch install ``` +LambdaPunch uses the `LAMBDA_TASK_ROOT` environment variable to find your project's Gemfile. If you are using a provided AWS Runtime container, this should be set for you to `/var/task`. However, if you are using your own base image, make sure to set this to your project directory. + +```dockerfile +ENV LAMBDA_TASK_ROOT=/app +``` + Installation with AWS Lambda via the [Lamby](https://lamby.custominktech.com/) v4 (or higher) gem can be done using Lamby's `handled_proc` config. For example, appends these to your `config/environments/production.rb` file. Here we are ensuring that the LambdaPunch DRb server is running and that after each Lamby request we notify LambdaPunch. ```ruby From 0253d5fc2865fd9c90ec72479698452c4d1452b7 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sat, 22 Apr 2023 11:30:58 -0400 Subject: [PATCH 06/12] The `error_handler` will now print the first 10 lines of a stack trace. --- CHANGELOG.md | 6 ++++++ lib/lambda_punch.rb | 1 + lib/lambda_punch/version.rb | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c652b0..f392121 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [1.1.2] - 2023-04-22 + +### Added + +- The `error_handler` will now print the first 10 lines of a stack trace. + ## [1.1.1] - 2023-04-16 ### Fixed diff --git a/lib/lambda_punch.rb b/lib/lambda_punch.rb index ae4654d..f0fb032 100644 --- a/lib/lambda_punch.rb +++ b/lib/lambda_punch.rb @@ -51,6 +51,7 @@ def handled!(context) def error_handler @error_handler ||= lambda do |e| logger.error "Queue#call::error => #{e.message}" + logger.error e.backtrace[0..10].join("\n") end end diff --git a/lib/lambda_punch/version.rb b/lib/lambda_punch/version.rb index f45eb76..b11c77f 100644 --- a/lib/lambda_punch/version.rb +++ b/lib/lambda_punch/version.rb @@ -1,3 +1,3 @@ module LambdaPunch - VERSION = "1.1.1" + VERSION = "1.1.2" end From b371c5d432b2b919293e91b4ab66d75876022b3f Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sat, 22 Apr 2023 11:42:37 -0400 Subject: [PATCH 07/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 67162fb..e934b28 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![LambdaPunch](https://user-images.githubusercontent.com/2381/123561512-c23fb580-d776-11eb-9780-71d606cd8f2c.png) -![Test](https://github.com/customink/lambda_punch/workflows/Test/badge.svg) +[![Test](https://github.com/customink/lambda_punch/actions/workflows/test.yml/badge.svg)](https://github.com/customink/lambda_punch/actions/workflows/test.yml) # 👊 LambdaPunch From 022a8fa76711e4d803e92f06771fee2d5f66c910 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sat, 22 Apr 2023 17:29:23 +0000 Subject: [PATCH 08/12] Update Dev Gems. Test Error Stack Trace. --- CHANGELOG.md | 6 ++ Gemfile.lock | 189 +++++++++++++++++++----------------- lib/lambda_punch/version.rb | 2 +- test/cases/queue_test.rb | 10 ++ 4 files changed, 117 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f392121..7a21421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [1.1.3] - 2023-04-22 + +### Added + +- Test for `error_handler` stack trace. + ## [1.1.2] - 2023-04-22 ### Added diff --git a/Gemfile.lock b/Gemfile.lock index 37a926f..d9994ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - lambda_punch (1.1.1) + lambda_punch (1.1.3) concurrent-ruby rake rb-inotify @@ -10,147 +10,158 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (6.1.4.1) - actionpack (= 6.1.4.1) - activesupport (= 6.1.4.1) + actioncable (7.0.4.3) + actionpack (= 7.0.4.3) + activesupport (= 7.0.4.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.4.1) - actionpack (= 6.1.4.1) - activejob (= 6.1.4.1) - activerecord (= 6.1.4.1) - activestorage (= 6.1.4.1) - activesupport (= 6.1.4.1) + actionmailbox (7.0.4.3) + actionpack (= 7.0.4.3) + activejob (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) mail (>= 2.7.1) - actionmailer (6.1.4.1) - actionpack (= 6.1.4.1) - actionview (= 6.1.4.1) - activejob (= 6.1.4.1) - activesupport (= 6.1.4.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.4.3) + actionpack (= 7.0.4.3) + actionview (= 7.0.4.3) + activejob (= 7.0.4.3) + activesupport (= 7.0.4.3) mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp rails-dom-testing (~> 2.0) - actionpack (6.1.4.1) - actionview (= 6.1.4.1) - activesupport (= 6.1.4.1) - rack (~> 2.0, >= 2.0.9) + actionpack (7.0.4.3) + actionview (= 7.0.4.3) + activesupport (= 7.0.4.3) + rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.4.1) - actionpack (= 6.1.4.1) - activerecord (= 6.1.4.1) - activestorage (= 6.1.4.1) - activesupport (= 6.1.4.1) + actiontext (7.0.4.3) + actionpack (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.4.1) - activesupport (= 6.1.4.1) + actionview (7.0.4.3) + activesupport (= 7.0.4.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.4.1) - activesupport (= 6.1.4.1) + activejob (7.0.4.3) + activesupport (= 7.0.4.3) globalid (>= 0.3.6) - activemodel (6.1.4.1) - activesupport (= 6.1.4.1) - activerecord (6.1.4.1) - activemodel (= 6.1.4.1) - activesupport (= 6.1.4.1) - activestorage (6.1.4.1) - actionpack (= 6.1.4.1) - activejob (= 6.1.4.1) - activerecord (= 6.1.4.1) - activesupport (= 6.1.4.1) - marcel (~> 1.0.0) + activemodel (7.0.4.3) + activesupport (= 7.0.4.3) + activerecord (7.0.4.3) + activemodel (= 7.0.4.3) + activesupport (= 7.0.4.3) + activestorage (7.0.4.3) + actionpack (= 7.0.4.3) + activejob (= 7.0.4.3) + activerecord (= 7.0.4.3) + activesupport (= 7.0.4.3) + marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.4.1) + activesupport (7.0.4.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) builder (3.2.4) coderay (1.1.3) - concurrent-ruby (1.1.9) + concurrent-ruby (1.2.2) crass (1.0.6) - erubi (1.10.0) + date (3.3.3) + erubi (1.12.0) ffi (1.15.5) - globalid (0.5.2) + globalid (1.1.0) activesupport (>= 5.0) - i18n (1.8.10) + i18n (1.12.0) concurrent-ruby (~> 1.0) - loofah (2.12.0) + loofah (2.20.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.1) + mail (2.8.1) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp marcel (1.0.2) method_source (1.0.0) mini_mime (1.1.2) - mini_portile2 (2.6.1) - minitest (5.14.4) + minitest (5.18.0) minitest-focus (1.3.1) minitest (>= 4, < 6) - nio4r (2.5.8) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) + net-imap (0.3.4) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.3.3) + net-protocol + nio4r (2.5.9) + nokogiri (1.14.3-aarch64-linux) + racc (~> 1.4) + nokogiri (1.14.3-arm64-darwin) racc (~> 1.4) - pry (0.14.1) + pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - racc (1.6.0) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.1.4.1) - actioncable (= 6.1.4.1) - actionmailbox (= 6.1.4.1) - actionmailer (= 6.1.4.1) - actionpack (= 6.1.4.1) - actiontext (= 6.1.4.1) - actionview (= 6.1.4.1) - activejob (= 6.1.4.1) - activemodel (= 6.1.4.1) - activerecord (= 6.1.4.1) - activestorage (= 6.1.4.1) - activesupport (= 6.1.4.1) + racc (1.6.2) + rack (2.2.6.4) + rack-test (2.1.0) + rack (>= 1.3) + rails (7.0.4.3) + actioncable (= 7.0.4.3) + actionmailbox (= 7.0.4.3) + actionmailer (= 7.0.4.3) + actionpack (= 7.0.4.3) + actiontext (= 7.0.4.3) + actionview (= 7.0.4.3) + activejob (= 7.0.4.3) + activemodel (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) bundler (>= 1.15.0) - railties (= 6.1.4.1) - sprockets-rails (>= 2.0.0) + railties (= 7.0.4.3) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (6.1.4.1) - actionpack (= 6.1.4.1) - activesupport (= 6.1.4.1) + rails-html-sanitizer (1.5.0) + loofah (~> 2.19, >= 2.19.1) + railties (7.0.4.3) + actionpack (= 7.0.4.3) + activesupport (= 7.0.4.3) method_source - rake (>= 0.13) + rake (>= 12.2) thor (~> 1.0) + zeitwerk (~> 2.5) rake (13.0.6) rb-inotify (0.10.1) ffi (~> 1.0) - sprockets (4.0.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - thor (1.1.0) + thor (1.2.1) timeout (0.3.2) - tzinfo (2.0.4) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.5.1) + zeitwerk (2.6.7) PLATFORMS aarch64-linux arm64-darwin-22 - x86_64-linux DEPENDENCIES lambda_punch! @@ -161,4 +172,4 @@ DEPENDENCIES rake BUNDLED WITH - 2.2.30 + 2.4.12 diff --git a/lib/lambda_punch/version.rb b/lib/lambda_punch/version.rb index b11c77f..2f00f73 100644 --- a/lib/lambda_punch/version.rb +++ b/lib/lambda_punch/version.rb @@ -1,3 +1,3 @@ module LambdaPunch - VERSION = "1.1.2" + VERSION = "1.1.3" end diff --git a/test/cases/queue_test.rb b/test/cases/queue_test.rb index d5e872e..3e429b7 100644 --- a/test/cases/queue_test.rb +++ b/test/cases/queue_test.rb @@ -36,6 +36,16 @@ class QueueTest < LambdaPunchSpec expect(out).must_include 'hell' end + it 'will log error backtraces' do + LambdaPunch.push do + hash_with_default_error = HashWithIndifferentAccess.new { |h| raise 'stack' } + hash_with_default_error['boom'] + end + out = capture(:stdout) { LambdaPunch::Queue.new.call } + expect(out).must_include 'lambda_punch/test/cases/queue_test.rb' + expect(out).must_include 'gems/activesupport' + end + it 'will allow a custom error handler to be used' do LambdaPunch.error_handler = lambda { |e| puts("test-#{e.class.name}") } LambdaPunch.push { raise('hell') } From 77e05e302bc59fd5588383a4188a53e2f875eb18 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sat, 29 Apr 2023 15:12:10 -0400 Subject: [PATCH 09/12] New lamby.cloud site and GitHub community organization. --- README.md | 18 +++++++++--------- lambda_punch.gemspec | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e934b28..608e130 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ ![LambdaPunch](https://user-images.githubusercontent.com/2381/123561512-c23fb580-d776-11eb-9780-71d606cd8f2c.png) -[![Test](https://github.com/customink/lambda_punch/actions/workflows/test.yml/badge.svg)](https://github.com/customink/lambda_punch/actions/workflows/test.yml) +[![Test](https://github.com/rails-lambda/lambda_punch/actions/workflows/test.yml/badge.svg)](https://github.com/rails-lambda/lambda_punch/actions/workflows/test.yml) # 👊 LambdaPunch -Lamby: Simple Rails & AWS Lambda Integration using Rack.Asynchronous background job processing for AWS Lambda with Ruby using [Lambda Extensions](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html). Inspired by the [SuckerPunch](https://github.com/brandonhilkert/sucker_punch) gem but specifically tooled to work with Lambda's invoke model. +Lamby: Simple Rails & AWS Lambda Integration using Rack.Asynchronous background job processing for AWS Lambda with Ruby using [Lambda Extensions](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html). Inspired by the [SuckerPunch](https://github.com/brandonhilkert/sucker_punch) gem but specifically tooled to work with Lambda's invoke model. -**For a more robust background job solution, please consider using AWS SQS with the [Lambdakiq](https://github.com/customink/lambdakiq) gem. A drop-in replacement for [Sidekiq](https://github.com/mperham/sidekiq) when running Rails in AWS Lambda using the [Lamby](https://lamby.custominktech.com/) gem.** +**For a more robust background job solution, please consider using AWS SQS with the [Lambdakiq](https://github.com/rails-lambda/lambdakiq) gem. A drop-in replacement for [Sidekiq](https://github.com/mperham/sidekiq) when running Rails in AWS Lambda using the [Lamby](https://lamby.cloud/) gem.** ## 🏗 Architecture @@ -24,7 +24,7 @@ Add this line to your project's `Gemfile` and then make sure to `bundle install` gem 'lambda_punch' ``` -Within your project or [Rails application's](https://lamby.custominktech.com/docs/anatomy) `Dockerfile`, add the following. Make sure you do this before you `COPY` your code. The idea is to implicitly use the default `USER root` since it needs permission to create an `/opt/extensions` directory. +Within your project or [Rails application's](https://lamby.cloud/docs/anatomy) `Dockerfile`, add the following. Make sure you do this before you `COPY` your code. The idea is to implicitly use the default `USER root` since it needs permission to create an `/opt/extensions` directory. ```dockerfile RUN gem install lambda_punch && lambda_punch install @@ -36,7 +36,7 @@ LambdaPunch uses the `LAMBDA_TASK_ROOT` environment variable to find your projec ENV LAMBDA_TASK_ROOT=/app ``` -Installation with AWS Lambda via the [Lamby](https://lamby.custominktech.com/) v4 (or higher) gem can be done using Lamby's `handled_proc` config. For example, appends these to your `config/environments/production.rb` file. Here we are ensuring that the LambdaPunch DRb server is running and that after each Lamby request we notify LambdaPunch. +Installation with AWS Lambda via the [Lamby](https://lamby.cloud/) v4 (or higher) gem can be done using Lamby's `handled_proc` config. For example, appends these to your `config/environments/production.rb` file. Here we are ensuring that the LambdaPunch DRb server is running and that after each Lamby request we notify LambdaPunch. ```ruby config.to_prepare { LambdaPunch.start_server! } @@ -78,7 +78,7 @@ end ### ActiveJob -You can use LambdaPunch with Rails' ActiveJob. **For a more robust background job solution, please consider using AWS SQS with the [Lambdakiq](https://github.com/customink/lambdakiq) gem.** +You can use LambdaPunch with Rails' ActiveJob. **For a more robust background job solution, please consider using AWS SQS with the [Lambdakiq](https://github.com/rails-lambda/lambdakiq) gem.** ```ruby config.active_job.queue_adapter = :lambda_punch @@ -90,7 +90,7 @@ Your function's timeout is the max amount to handle the request and process all If your application integrates with API Gateway (which has a 30 second timeout) then it is possible your function can be set with a higher timeout to perform background work. Since work is done after each invoke, the LambdaPunch queue should be empty when your function receives the `SHUTDOWN` event. If jobs are in the queue when this happens they will have two seconds max to work them down before being lost. -**For a more robust background job solution, please consider using AWS SQS with the [Lambdakiq](https://github.com/customink/lambdakiq) gem.** +**For a more robust background job solution, please consider using AWS SQS with the [Lambdakiq](https://github.com/rails-lambda/lambdakiq) gem.** ### Logging @@ -140,7 +140,7 @@ You can also run the `./bin/console` command for an interactive prompt within th ## 💖 Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/customink/lambda_punch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/customink/lambda_punch/blob/main/CODE_OF_CONDUCT.md). +Bug reports and pull requests are welcome on GitHub at https://github.com/rails-lambda/lambda_punch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/rails-lambda/lambda_punch/blob/main/CODE_OF_CONDUCT.md). ## 👩‍⚖️ License @@ -148,4 +148,4 @@ The gem is available as open source under the terms of the [MIT License](https:/ ## 🤝 Code of Conduct -Everyone interacting in the LambdaPunch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/customink/lambda_punch/blob/main/CODE_OF_CONDUCT.md). +Everyone interacting in the LambdaPunch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rails-lambda/lambda_punch/blob/main/CODE_OF_CONDUCT.md). diff --git a/lambda_punch.gemspec b/lambda_punch.gemspec index f6383b0..f1eeea2 100644 --- a/lambda_punch.gemspec +++ b/lambda_punch.gemspec @@ -7,11 +7,11 @@ Gem::Specification.new do |spec| spec.email = ["ken@metaskills.net"] spec.summary = "LambdaPunch: Async Processing using Lambda Extensions" spec.description = "LambdaPunch: Async Processing using Lambda Extensions" - spec.homepage = "https://github.com/customink/lambda_punch" + spec.homepage = "https://github.com/rails-lambda/lambda_punch" spec.license = "MIT" spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/customink/lambda_punch" - spec.metadata["changelog_uri"] = "https://github.com/customink/lambda_punch/blob/main/CHANGELOG.md" + spec.metadata["source_code_uri"] = "https://github.com/rails-lambda/lambda_punch" + spec.metadata["changelog_uri"] = "https://github.com/rails-lambda/lambda_punch/blob/main/CHANGELOG.md" spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|images)/}) } end From 5e167fd7d5315a3584afc9307d8aa75632f71c93 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sun, 9 Jun 2024 23:17:27 +0000 Subject: [PATCH 10/12] The to now rescue errors. Fixes #18 --- CHANGELOG.md | 6 ++++++ lib/lambda_punch/server.rb | 1 + lib/lambda_punch/version.rb | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a21421..afea4af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [1.1.4] - 2024-06-09 + +### Changed + +- The `LambdaPunch.start_server!` to now rescue `Errno::EADDRINUSE` errors. + ## [1.1.3] - 2023-04-22 ### Added diff --git a/lib/lambda_punch/server.rb b/lib/lambda_punch/server.rb index c2890aa..29448b5 100644 --- a/lib/lambda_punch/server.rb +++ b/lib/lambda_punch/server.rb @@ -20,6 +20,7 @@ def start! def initialize @queue = Queue.new DRb.start_service self.class.uri, @queue + rescue Errno::EADDRINUSE end end diff --git a/lib/lambda_punch/version.rb b/lib/lambda_punch/version.rb index 2f00f73..ba7693d 100644 --- a/lib/lambda_punch/version.rb +++ b/lib/lambda_punch/version.rb @@ -1,3 +1,3 @@ module LambdaPunch - VERSION = "1.1.3" + VERSION = "1.1.4" end From b92935e6e751e6c2125e3372485906bfffa05dee Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sun, 9 Jun 2024 19:20:14 -0400 Subject: [PATCH 11/12] Prepare for v1.1.4 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index d9994ab..7c21628 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - lambda_punch (1.1.3) + lambda_punch (1.1.4) concurrent-ruby rake rb-inotify From 117a2da7eb4f0184a784a2b252b531a70e0ae7e3 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sun, 9 Jun 2024 23:24:39 +0000 Subject: [PATCH 12/12] Update dev deps to latest. --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7c21628..8f6251b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -172,4 +172,4 @@ DEPENDENCIES rake BUNDLED WITH - 2.4.12 + 2.2.3