Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to create a scheduled event to execute a specific job? #12

Answered by metaskills
fabiensebban asked this question in Q&A
Discussion options

I created a scheduled event in the template.yaml file but I don't know how to tell the schedule to run a specific job.
Someone knows how?

Here is the schedule I added to the Job resources:

ScheduledEvent:
 Type: Schedule
 Properties:
 Schedule: cron(*/1 * * * ? *)
 Enabled: True
You must be logged in to vote

YO! Sorry for the delayed response. Did you find an answer to your question? What you have above looks fine. Assuming you added that under the Events: property?

Maybe too I should change this to a yes or maybe? https://github.com/customink/lambdakiq#common-questions

Replies: 3 comments 3 replies

Comment options

YO! Sorry for the delayed response. Did you find an answer to your question? What you have above looks fine. Assuming you added that under the Events: property?

Maybe too I should change this to a yes or maybe? https://github.com/customink/lambdakiq#common-questions

You must be logged in to vote
2 replies
Comment options

Hey! It's OK. Thank you for your reply.
I did this in my app.rb file:

ENV['RAILS_SERVE_STATIC_FILES'] = '1'
require_relative 'config/boot'
require 'dotenv' ; Dotenv.load ".env.#{ENV['RAILS_ENV']}"
require 'lamby'
require_relative 'config/application'
require_relative 'config/environment'
$app = Rack::Builder.new { run Rails.application }.to_app
def handler(event:, context:)
 if event['job_name']
 Object.const_get(event['job_name']).perform_later
 elsif Lambdakiq.jobs?(event)
 Lambdakiq.handler(event)
 else
 Lamby.handler $app, event, context, rack: :http
 end
end

And I created a schedule event adding this in template.yml under JobLambda -> Properties -> Events:

ScheduledEvent:
 Type: Schedule
 Properties:
 DeadLetterConfig: 
 Arn: !GetAtt JobsDLQueue.Arn
 Input: '{"job_name": "TheCronJob"}'
 Schedule: cron(*/1 * * * ? *)
 Enabled: True

It seems to work but I feel like it is not the correct way to get the job done. I will tell you if I find another way.

Comment options

That actually looks good to me!

Answer selected by metaskills
Comment options

Hi again @metaskills :)
I am facing the same issue right now since the new Lamby version came out. I don't have access to the old app.rb file with the new version so it is not possible to handle Scheduled Events like I used to do.

Maybe I can just change my Dockerfile so it runs this command: CMD ["app.App::Handler.process"]
And then, create my own app.rb handler like it is explained in the aws_lambda_ric gem documentation:

module App
 class Handler
 def self.process(event:, context:)
 "Hello World!"
 end
 end
end

What do you think? Is is good practice? Is there another way to run a job through Scheduled Events?

You must be logged in to vote
1 reply
Comment options

I just tested this approch and it seems to be working pretty good. Now I can run a scheduled event and I can event send an event to the job Lambda with the body bellow to force a specific job execution:

{
 "job_name": "MyJob"
}
Comment options

Cool, did you figure out your CMD could be something like this?

CMD ["config/environment.App::Handler.process"]

Or whatever method is inside your application?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /