简体   繁体   中英

schedule an API call inside unix/python environment

I want to implement the schedule tweet feature as similar to hootsuite or buffer.

The way I have designed my current architecture is - a cron job runs every minute, which evokes a shell script, which fires a python/django command to see if there is any scheduled tweet in the database for current time. If yes, make an API call to twitter.

Is there a better way of doing it?

可以使用django-celery安排相同的过程

It's hard to define what's "better" way of doing it since it depends on implementation/problem.

For simple implementations I would go the same route you went, that is cron. If that's OK with you, ie there are no other problems you want to avoid I would advise sticking with it.

If you have need for something else you can for example:

  • Start long running process/daemon which will track time and run/spawn actions on timer events
  • Start long running process + task queue so that queue will send data to process when it should be run (Proposed by @Siva django-celery is such solution)
  • Do a super-simple cron-independent solution which runs the tasks then sleeps for set amount of seconds (30s).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM