# REST Implementation for Scheduler in Legacy UI Module

**URL:** <https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801>\
**Category:** Development\
**Tags:** legacy-ui, restws\
**Created:** [August 9, 2017, 2:54am UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801 "2017-08-09T02:54:53Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![suthagar23](https://talk.openmrs.org/user_avatar/talk.openmrs.org/suthagar23/32/6342_2.png) [@suthagar23](https://talk.openmrs.org/u/suthagar23)\
**Post date:** [August 9, 2017, 2:54am UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/1 "2017-08-09T02:54:54Z")

</div>

I am working on [RESTWS-674](https://issues.openmrs.org/browse/RESTWS674) ticket to implement REST for Scheduler in LegacyUI module.

In the dashboard, Scheduler contains a list of task definitions. Here I wanted to follow two classes from OpenMRS Core

- Schedule.java - [https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/scheduler/Schedule.java](https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/scheduler/Schedule.java)
- TaskDefinition.java - [https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/scheduler/TaskDefinition.java](https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/scheduler/TaskDefinition.java)

Here I am going to expose this following details through the REST serveices,

**TaskDefinition** - GET /rest/v1/taskdefinition/

1. uuid
2. name
3. descriptio
4. taskClass
5. startTime
6. lastExecutionTime
7. repeatInterval
8. startOnStartup
9. started
10. properties

@dkayiwa Is it ok with the implementation ?

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [August 9, 2017, 3:01pm UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/2 "2017-08-09T15:01:23Z")

</div>

Looks like a good start! 🙂

---

<div class="post-metadata">

**Author:** ![wyclif](https://talk.openmrs.org/user_avatar/talk.openmrs.org/wyclif/32/19607_2.png) [@wyclif](https://talk.openmrs.org/u/wyclif)\
**Post date:** [August 10, 2017, 2:14pm UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/3 "2017-08-10T14:14:47Z")

</div>

I don’t think `Schedule` is really part of the public API, in fact don’t think it’s used anywhere, I’d say just ignore it.

---

<div class="post-metadata">

**Author:** ![suthagar23](https://talk.openmrs.org/user_avatar/talk.openmrs.org/suthagar23/32/6342_2.png) [@suthagar23](https://talk.openmrs.org/u/suthagar23)\
**Post date:** [August 11, 2017, 5:05am UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/4 "2017-08-11T05:05:17Z")

</div>

@wyclifHere I wanted to implement Manage Scheduler functionalities in OWA, So I need to implement REST services for TaskDefinitions to complete that task.

---

<div class="post-metadata">

**Author:** ![suthagar23](https://talk.openmrs.org/user_avatar/talk.openmrs.org/suthagar23/32/6342_2.png) [@suthagar23](https://talk.openmrs.org/u/suthagar23)\
**Post date:** [August 16, 2017, 5:24pm UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/5 "2017-08-16T17:24:42Z")

</div>

@dkayiwa Can you review it please

> <https://github.com/openmrs/openmrs-module-webservices.rest/pull/293>

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [August 16, 2017, 5:52pm UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/6 "2017-08-16T17:52:44Z")

</div>

You need to add some tests.

---

<div class="post-metadata">

**Author:** ![suthagar23](https://talk.openmrs.org/user_avatar/talk.openmrs.org/suthagar23/32/6342_2.png) [@suthagar23](https://talk.openmrs.org/u/suthagar23)\
**Post date:** [August 17, 2017, 4:39pm UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/7 "2017-08-17T16:39:17Z")

</div>

@dkayiwa I have added some test cases, but getting some errors. Can you take a look at here, Test class : [https://pastebin.com/nTZXv2fQ](https://pastebin.com/nTZXv2fQ) Error trace : [https://pastebin.com/XP7KHCPr](https://pastebin.com/XP7KHCPr)

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [August 17, 2017, 6:24pm UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/8 "2017-08-17T18:24:44Z")

</div>

When you fetch that task with getTaskByName, does it actually exist?

---

<div class="post-metadata">

**Author:** ![suthagar23](https://talk.openmrs.org/user_avatar/talk.openmrs.org/suthagar23/32/6342_2.png) [@suthagar23](https://talk.openmrs.org/u/suthagar23)\
**Post date:** [August 17, 2017, 6:26pm UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/9 "2017-08-17T18:26:30Z")

</div>

Yah, I can get it through the REST Request, But can’t through the Test Case

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [August 17, 2017, 6:44pm UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/10 "2017-08-17T18:44:39Z")

</div>

You can mock it, or else add a test dataset [https://wiki.openmrs.org/display/docs/Unit+Testing+with+Database+Data](https://wiki.openmrs.org/display/docs/Unit+Testing+with+Database+Data)

---

<div class="post-metadata">

**Author:** ![suthagar23](https://talk.openmrs.org/user_avatar/talk.openmrs.org/suthagar23/32/6342_2.png) [@suthagar23](https://talk.openmrs.org/u/suthagar23)\
**Post date:** [August 20, 2017, 6:46pm UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/11 "2017-08-20T18:46:10Z")

</div>

Finally, I have implemented two resources for this purpose and all are working as expected 🙂

**TaskDefinition** - _/openmrs/ws/rest/v1/taskdefinition_

- GET - return all the registered tasks

- POST - Create new definition

- POST/{taskName} - update the task definition

**TaskAction** - _/openmrs/ws/rest/v1/taskaction_

- POST - post the action, task information to do Action types : SCHEDULETASK, SHUTDOWNTASK, RESCHEDULETASK, RESCHEDULEALLTASK, DELETE, ONSTARTUP, ONSHUTDOWN Post Body : {“action” : “scheduletask”, “tasks” : [“sample”], “allTasks” : true }

cc : @dkayiwa

---

<div class="post-metadata">

**Author:** ![suthagar23](https://talk.openmrs.org/user_avatar/talk.openmrs.org/suthagar23/32/6342_2.png) [@suthagar23](https://talk.openmrs.org/u/suthagar23)\
**Post date:** [August 29, 2017, 10:48am UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/12 "2017-08-29T10:48:18Z")

</div>

@dkayiwa I have updated the PR but failed in Travis.

I could get success with my local project but Travis check was failed. Can you please take a look on this error?

[https://travis-ci.org/openmrs/openmrs-module-webservices.rest/builds/269501880?utm\_source=github\_status&utm\_medium=notification](https://travis-ci.org/openmrs/openmrs-module-webservices.rest/builds/269501880?utm_source=github_status&utm_medium=notification)

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [August 29, 2017, 2:01pm UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/13 "2017-08-29T14:01:40Z")

</div>

Did you look at the failure log?

---

<div class="post-metadata">

**Author:** ![suthagar23](https://talk.openmrs.org/user_avatar/talk.openmrs.org/suthagar23/32/6342_2.png) [@suthagar23](https://talk.openmrs.org/u/suthagar23)\
**Post date:** [August 30, 2017, 4:30am UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/14 "2017-08-30T04:30:33Z")

</div>

@dkayiwa It showed me the COMPILATION ERROR in the Travis check. But I can compile and build it locally without any errors.

```
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/travis/build/openmrs/openmrs-module-webservices.rest/omod1.8/src/main/java
/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskActionResource1_8.java:[35,8] org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.TaskActionResource1_8 
is not abstract and does not override abstract method getCREATEModel(org.openmrs.module.webservices.rest.web.representation.Representation) in
org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler
```

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [August 30, 2017, 6:30am UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/15 "2017-08-30T06:30:23Z")

</div>

Did you pull the latest upstream changes into your local version?

---

<div class="post-metadata">

**Author:** ![suthagar23](https://talk.openmrs.org/user_avatar/talk.openmrs.org/suthagar23/32/6342_2.png) [@suthagar23](https://talk.openmrs.org/u/suthagar23)\
**Post date:** [August 30, 2017, 10:09am UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/16 "2017-08-30T10:09:11Z")

</div>

@dkayiwa

Yah, with in a short time, the code has been changed in the master due to the other PRs 😂. Thanks for the advice!

Now It is working without any problem 😃

---

<div class="post-metadata">

**Author:** ![tendomart](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tendomart/32/6753_2.png) [@tendomart](https://talk.openmrs.org/u/tendomart)\
**Post date:** [December 11, 2020, 7:31am UTC](https://talk.openmrs.org/t/rest-implementation-for-scheduler-in-legacy-ui-module/12801/17 "2020-12-11T07:31:42Z")

</div>

> [@suthagar23](#):
>
> POST - post the action, task information to do Action types : SCHEDULETASK, SHUTDOWNTASK, RESCHEDULETASK, RESCHEDULEALLTASK, DELETE, ONSTARTUP, ONSHUTDOWN Post Body : {“action” : “scheduletask”, “tasks” : [“sample”], “allTasks” : true }

@suthagar23 do you have a real example of the post payload for the **TaskAction**?
