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 f3f99e0..afea4af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,38 @@ +## [1.1.4] - 2024-06-09 + +### Changed + +- The `LambdaPunch.start_server!` to now rescue `Errno::EADDRINUSE` errors. + +## [1.1.3] - 2023-04-22 + +### Added + +- Test for `error_handler` stack trace. + +## [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 + +- The `lambda_punch` install file. + +## [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/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..8f6251b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - lambda_punch (1.0.3) + lambda_punch (1.1.4) concurrent-ruby rake rb-inotify @@ -10,143 +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) - ffi (1.15.4) - globalid (0.5.2) + date (3.3.3) + erubi (1.12.0) + ffi (1.15.5) + 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) - minitest (5.14.4) + minitest (5.18.0) minitest-focus (1.3.1) minitest (>= 4, < 6) - nio4r (2.5.8) - nokogiri (1.12.5-x86_64-linux) + 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) - timeout (0.2.0) - tzinfo (2.0.4) + thor (1.2.1) + timeout (0.3.2) + 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 - x86_64-linux + aarch64-linux + arm64-darwin-22 DEPENDENCIES lambda_punch! @@ -157,4 +172,4 @@ DEPENDENCIES rake BUNDLED WITH - 2.2.30 + 2.2.3 diff --git a/README.md b/README.md index 3c821e6..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/workflows/Test/badge.svg) +[![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 @@ -18,35 +18,42 @@ 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.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. -```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. +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 -RUN bundle exec rake lambda_punch:install +ENV LAMBDA_TASK_ROOT=/app ``` -If you are using `LambdaPunch` with a non-Rails project, add this to your Rake file +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 -spec = Gem::Specification.find_by_name 'lambda_punch' -load "#{spec.gem_dir}/lib/lambda_punch/tasks/install.rake" +config.to_prepare { LambdaPunch.start_server! } +config.lamby.handled_proc = Proc.new do |_event, context| + LambdaPunch.handled!(context) +end +``` + +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 +LambdaPunch.start_server! +def handler(event:, context:) + # ... +ensure + LambdaPunch.handled!(context) +end ``` ## 🧰 Usage @@ -59,12 +66,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. +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 -def handler(event:, context:) - Lamby.handler $app, event, context -ensure +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 @@ -72,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 @@ -84,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 @@ -134,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 @@ -142,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/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 new file mode 100755 index 0000000..3612d21 --- /dev/null +++ b/exe/lambda_punch @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby + +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' + +Rake::Task["lambda_punch:#{command}"].invoke 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 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/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 93259dd..ba7693d 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.4" 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') } 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