Thaina Yu
Thaina Yu

Reputation: 1512

Are there a cloud service that was reliably schedule execute a job at exact time?

I was writing server with serverless model, currently aws lambda. And have a requirement to run a job on exact datetime

Currently now I was running a cron job with aws cloudwatch to execute my server every minute, find all tasks which has timestamp older than present then do those task. Which is both wasteful and sometimes make a delay or in advanced by one minute from the actual time it need (because cloudwatch has maximum frequency only one ping per one minute). Not a desirable approach

And the work is not the same everyday. It can be dynamic datetime by client to ping my server

I wish there should be some service that like a message queue but can actively call target URL on scheduling timestamp. Is there something like that? It could be any service outside aws if it can put a URL for request

Thank you very much

Upvotes: 2

Views: 833

Answers (7)

Stefan Majiros
Stefan Majiros

Reputation: 584

Another solution would be to use EventBridge scheduler - https://docs.aws.amazon.com/scheduler/latest/UserGuide/schedule-types.html#one-time

Upvotes: 0

Thaina Yu
Thaina Yu

Reputation: 1512

Other solutions seem promising but there are another solution I found

using step functions wait state

http://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html

I cannot use it in my region yet because my region is singapore and it cannot be used across region. Currently now I would try to see a dynamodb solution above

As of 2018 step function was generaly available and work as expected

Upvotes: 1

Thaina Yu
Thaina Yu

Reputation: 1512

As of 2018 there was Azure Logic Apps. An equivalence service to aws step function on azure. It contains delay connector that can schedule delay time

https://learn.microsoft.com/en-us/azure/connectors/connectors-native-delay

Upvotes: 0

Carlos Gomez
Carlos Gomez

Reputation: 469

You likely already found a solution to this but my service https://posthook.io may be good fit for your use case. It lets you schedule 'hooks' with an API call like this:

curl https://api.posthook.io/v1/hooks \
-H 'X-API-Key: ${POSTHOOK_API_KEY}' \
-H 'Content-Type: application/json' \
-d '{
    "path": "/webhooks/ph/event_reminder",
    "postAt": "2018-07-03T01:11:55Z",
    "data": {
        "eventID": 25
    }
}'

Then from your lamdba function you can either use the data you passed in as data or the hook's unique ID to look something up in your database and do the needed work. A free account allows you to schedule 500 of these requests a month.

Upvotes: 1

Noel Llevares
Noel Llevares

Reputation: 16037

You can use DynamoDB with TTL, DynamoDB Streams and AWS Lambda for this.

Since the schedule is dynamic and coming from the user, you can save those items in a DynamoDB table with its TTL set to the scheduled execution time.

When the TTL is reached for an item, it will create a DynamoDB Stream which you can then use to trigger a Lambda function.

References:

Upvotes: 2

Trent Bartlem
Trent Bartlem

Reputation: 2253

As a workaround, why not have the lambda wake on a Cloudwatch alert, then check for tasks every 5 seconds until 55 seconds have elapsed?

Upvotes: 1

Tofig Hasanov
Tofig Hasanov

Reputation: 3709

Have you considered getting small EC2 instance and then set up cron jobs there? It can then publish events to SNS or directly call required tasks. And you should be able to schedule new jobs dynamically as well.

Upvotes: 2

Related Questions