|
| 1 | +import datetime |
1 | 2 | from .service import Service
|
2 | 3 |
|
3 | 4 |
|
@@ -69,3 +70,115 @@ def cancel(self, key, cancellation_key, recipients=None):
|
69 | 70 | }
|
70 | 71 |
|
71 | 72 | return self.client.request("post", endpoint, payload=params)
|
| 73 | + |
| 74 | + def create_schedules( |
| 75 | + self, |
| 76 | + key, |
| 77 | + recipients, |
| 78 | + repeats, |
| 79 | + data={}, |
| 80 | + scheduled_at=datetime.datetime.now(), |
| 81 | + actor=None, |
| 82 | + tenant=None): |
| 83 | + """ |
| 84 | + Creates schedules for recipients. |
| 85 | +
|
| 86 | + Args: |
| 87 | + key (str): The key of the workflow to invoke. |
| 88 | +
|
| 89 | + actor (str | dict[str, Any]): An optional reference for who/what performed the action. This can be A) a user |
| 90 | + id, B) an object reference, or C) a dictionary with data to identify a user or object. |
| 91 | +
|
| 92 | + recipients (list[str | dict[str, Any]]): A list of recipients that should be notified. This can be a list of |
| 93 | + A) user ids, B) object references, C) dictionaries with data to identify a user or object, or D) a |
| 94 | + combination thereof. |
| 95 | +
|
| 96 | + data (dict): Any data to be passed to the scheduled trigger call. |
| 97 | +
|
| 98 | + scheduled_at (datetime): Date when the schedule must start |
| 99 | +
|
| 100 | + tenant (str): An optional identifier for the tenant object that the notifications belong to. |
| 101 | +
|
| 102 | + Returns: |
| 103 | + list[dict]: list of created schedules |
| 104 | + """ |
| 105 | + endpoint = '/schedules' |
| 106 | + |
| 107 | + params = { |
| 108 | + 'workflow': key, |
| 109 | + 'recipients': recipients, |
| 110 | + 'repeats': repeats, |
| 111 | + 'actor': actor, |
| 112 | + 'data': data, |
| 113 | + 'tenant': tenant, |
| 114 | + 'scheduled_at': scheduled_at.isoformat() |
| 115 | + } |
| 116 | + |
| 117 | + return self.client.request("post", endpoint, payload=params) |
| 118 | + |
| 119 | + def update_schedules( |
| 120 | + self, |
| 121 | + schedule_ids, |
| 122 | + schedule_attrs): |
| 123 | + """ |
| 124 | + Updates schedules with given attributes. |
| 125 | +
|
| 126 | + Args: |
| 127 | + schedule_ids (list[str]): the ids of the schedules to be updated (max 100) |
| 128 | +
|
| 129 | + schedule_attrs (dict): Schedule attributes to be updated, these can be: repeats, actor, data and tenant. |
| 130 | +
|
| 131 | + Returns: |
| 132 | + list[dict]: list of updated schedules |
| 133 | + """ |
| 134 | + endpoint = '/schedules' |
| 135 | + |
| 136 | + schedule_attrs['schedule_ids'] = schedule_ids |
| 137 | + |
| 138 | + return self.client.request("put", endpoint, payload=schedule_attrs) |
| 139 | + |
| 140 | + def list_schedules( |
| 141 | + self, |
| 142 | + key, |
| 143 | + options = {}): |
| 144 | + """ |
| 145 | + List workflow schedules |
| 146 | +
|
| 147 | + Args: |
| 148 | + key (string): workflow key |
| 149 | +
|
| 150 | + options (dict): Supports the following optional arguments: |
| 151 | + - page_size: specify size of the page to be returned by the api. (max limit: 50) |
| 152 | + - after: after cursor for pagination |
| 153 | + - before: before cursor for pagination |
| 154 | + - tenant: tenant_id to filter schedules with |
| 155 | + - recipients: list of recipients to filter schedules with |
| 156 | +
|
| 157 | + Returns: |
| 158 | + dict: list of updated schedules |
| 159 | + """ |
| 160 | + |
| 161 | + endpoint = '/schedules' |
| 162 | + options['workflow'] = key |
| 163 | + |
| 164 | + return self.client.request('get', endpoint, payload=options) |
| 165 | + |
| 166 | + def delete_schedules( |
| 167 | + self, |
| 168 | + schedule_ids): |
| 169 | + """ |
| 170 | + Delete schedules. |
| 171 | +
|
| 172 | + Args: |
| 173 | + schedule_ids (list[str]): the ids of the schedules to be updated (max 100) |
| 174 | +
|
| 175 | + Returns: |
| 176 | + list[dict]: list of updated schedules |
| 177 | + """ |
| 178 | + endpoint = '/schedules' |
| 179 | + |
| 180 | + params = { |
| 181 | + 'schedule_ids': schedule_ids, |
| 182 | + } |
| 183 | + |
| 184 | + return self.client.request("delete", endpoint, payload=params) |
0 commit comments