Friday, 12 October 2018

Exposing Python APIs for users

In continuation to User Interface for filtering objects in Python

I want to expose APIs in python for my workload automation software. I have created a user facing model class called as "Job".

Job
- Id
- JobName
- StartTime
- EndTime
- CommandToExecute
- ...

I want user APIs for satisfying following use-cases:

  1. Ability to query Jobs given a criteria (e.g. return jobs that ran in a given duration, return jobs in failed state).
  2. Ability to create and run jobs using python API.
  3. Ability to take control actions like rerun already ran job, kill running job etc.

I am thinking of providing following method in my user API.

Job get_jobs(Filter) - This serves/solves use-case#1

I am not sure how should I solve use-case #2 and #3 above. I have couple of solutions in my mind but I am not sure which one is best.

Solution#1. For creating Jobs users can directly instantiate Object of class Job. I will provide methods in Job Model class itself for running and re-running Job. Users will create instance of Job class and call methods (run, rerun, kill etc) on Job object.

Solution#2. Along with get_job API, expose separate APIs for control actions like run and rerun in user interface.

Job get_job(Filter) 
boolean run_job(Job)
boolean rerun_job(Job)
...

What if in future I want to support many more control actions on Job object (for e.x. hold, resume etc.). If I go with solution#2, I will end up creating lots of methods in user API.

I am not sure which of the following approach is better and why? Or there is some other way I should think of.



from Exposing Python APIs for users

No comments:

Post a Comment