How to test an Afterburner job from Lambda test events

question

#1

Hello,

My app is using Afterburner because I need the gem active_elastic_job to send sqs messages to my queue. Those messages are processed by an Elastic Beanstalk worker.

Sometimes I need to manually send messages (for test purpose) to the queue and I thought about creating a specific job in my Afterburner app that sends a message to the queue.

Is there a way to run a job on an Afterburner app by using the Lambda test events the same way is done in this post: https://blog.boltops.com/2019/01/03/serverless-ruby-cron-jobs-with-jets-route53-backup ?

Thank you!


#2

There’s a way, it’s a bit hacky though.

What happens with Jets Afterburner mode is that it generates a wrapper Jets application and then proxies requests from the Jets app to the Rails app. This was a design choice.

As a part of the Jets application generation process, it’ll merge in the files from the .jets folder. So you could create a .jets/app/jobs/hard_job.rb. Again, a little bit hacky. Haven’t tested in a while, but it should work.


#3

Thank you!

I created a .jets/app/jobs/ping_job.rb file and I see it in my lambda functions under app/job folder.
But only the following lambda functions were created after deploy :

[PROJECT NAME]-[ENV]-jets-rack_controller-process
[PROJECT NAME]-[ENV]-jets-preheat_job-warm
[PROJECT NAME]-[ENV]-jets-preheat_job-torch

I was expected to see a [PROJECT NAME]-[ENV]-jets-job-ping lambda function.

I tried to remove the cloudfomration template a re-deploy the project but it didn’t work.

Do I have to add something for jets understands it has to create the job lambda function?


#4

I see. The path structure is confusing since .jets/app contains the wrapper Jets app. So I renamed it to .jets/project in v1.9.23 in PR https://github.com/tongueroo/jets/pull/300 This will be less confusing

  • v1.9.23 and above: .jets/project/app/jobs/ping_job.rb
  • v1.9.22 and below: .jets/app/app/jobs/ping_job.rb # the double app/app is pretty confusing

Added an error message let users know to rename the folder to .jets/project in newer versions also.


#5

Thank you so much!
It works perfectly!