-
Notifications
You must be signed in to change notification settings - Fork 8
How to create a scheduled event to execute a specific job? #12
-
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
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
That actually looks good to me!
Beta Was this translation helpful? Give feedback.
All reactions
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
-
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" }
Beta Was this translation helpful? Give feedback.
All reactions
-
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?
Beta Was this translation helpful? Give feedback.