Add support for subscriptions and scheduled actions in service config #19

Closed
opened 2017-06-19 01:37:15 +00:00 by jamie · 9 comments
jamie commented 2017-06-19 01:37:15 +00:00 (Migrated from git.hazaar.io)

Right now it is only possible to schedule actions and subscribe to events programatically. This is normally done in the service init() method. This is fine, but it means that you also have to handle the APPLICATION_ENV programatically if it is a factor. This is the case if you want to subscribe to an event in development only, to assist with development but you don't want to allow that in production.

We should be using the service config file to handle all this, that way the APPLICATION_ENV is always taken into account when loading the config and we can easily subscribe/schedule different things based on the environment.

Right now it is only possible to schedule actions and subscribe to events programatically. This is normally done in the service init() method. This is fine, but it means that you also have to handle the APPLICATION_ENV programatically if it is a factor. This is the case if you want to subscribe to an event in development only, to assist with development but you don't want to allow that in production. We should be using the service config file to handle all this, that way the APPLICATION_ENV is always taken into account when loading the config and we can easily subscribe/schedule different things based on the environment.
jamie commented 2017-06-19 01:37:40 +00:00 (Migrated from git.hazaar.io)

added ~164 label

added ~164 label
jamie commented 2017-06-19 01:40:53 +00:00 (Migrated from git.hazaar.io)
created branch [`19-add-support-for-subscriptions-and-scheduled-actions-in-service-config`](https://git.hazaarlabs.com/hazaar/hazaar-warlock/compare/master...19-add-support-for-subscriptions-and-scheduled-actions-in-service-config)
jamie commented 2017-06-19 01:42:58 +00:00 (Migrated from git.hazaar.io)
created branch [`19-add-support-for-subscriptions-and-scheduled-actions-in-service-config`](https://git.hazaarlabs.com/hazaar/hazaar-warlock/compare/master...19-add-support-for-subscriptions-and-scheduled-actions-in-service-config)
jamie commented 2017-06-19 02:38:01 +00:00 (Migrated from git.hazaar.io)

Here is an example of the supported config format:

    "servicename": {
      "enabled": true,
      "heartbeat": 300,
      "subscribe": {
        "do_the_thing": "thingToBeDone",
        "set_the_date": "setTheDate"
      },
      "schedule": [
        {
          "delay": 30,
          "action": "postStartThing"
        },
        {
          "when": "0 9 * * 1-5",
          "action": "checkPendingThings"
        },
        {
          "interval": 300,
          "action": "checkFailedThings"
        },
        {
          "when": "0 0 * * *",
          "action": "synchroniseThings"
        }
      ]
    }

This config should be pretty obvious. But to explain, it will subscribe to two events, do_the_thing and set_the_date. It will also schedule the following actions:

  • postStartThing will start 30 seconds after the service starts
  • checkPendingThings will execute at 9am every weekday Monday to Friday
  • checkFailedThings will execute every 5 minutes
  • synchroniseThings will execute at midnight every day

I have purposely not added support for schedules at a specific date time. This seemed like a silly thing to put in a config file as once it's executed the config is useless. Calling $this->schedule() inside a service is more likely how this will be used.

Here is an example of the supported config format: ``` "servicename": { "enabled": true, "heartbeat": 300, "subscribe": { "do_the_thing": "thingToBeDone", "set_the_date": "setTheDate" }, "schedule": [ { "delay": 30, "action": "postStartThing" }, { "when": "0 9 * * 1-5", "action": "checkPendingThings" }, { "interval": 300, "action": "checkFailedThings" }, { "when": "0 0 * * *", "action": "synchroniseThings" } ] } ``` This config should be pretty obvious. But to explain, it will subscribe to two events, **do_the_thing** and **set_the_date**. It will also schedule the following actions: * **postStartThing** will start 30 seconds after the service starts * **checkPendingThings** will execute at 9am every weekday Monday to Friday * **checkFailedThings** will execute every 5 minutes * **synchroniseThings** will execute at midnight every day I have purposely not added support for schedules at a specific date time. This seemed like a silly thing to put in a config file as once it's executed the config is useless. Calling *$this->schedule()* inside a service is more likely how this will be used.
jamie commented 2017-06-19 04:57:00 +00:00 (Migrated from git.hazaar.io)

mentioned in commit f23410ea69

mentioned in commit f23410ea690f7cbec84f3a6db762e1ef3c81072a
jamie commented 2017-06-19 04:57:37 +00:00 (Migrated from git.hazaar.io)

mentioned in merge request !4

mentioned in merge request !4
jamie commented 2017-06-19 04:57:53 +00:00 (Migrated from git.hazaar.io)

closed via commit f23410ea69

closed via commit f23410ea690f7cbec84f3a6db762e1ef3c81072a
jamie commented 2017-06-19 04:57:54 +00:00 (Migrated from git.hazaar.io)

closed via commit acf76f22d0

closed via commit acf76f22d01baa7c9caaf6602cc2ee8428a004ce
jamie commented 2017-06-19 04:57:54 +00:00 (Migrated from git.hazaar.io)

closed via merge request !4

closed via merge request !4
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/hazaar-warlock#19
No description provided.