The Task Class
The Task
class is the core construct of Cadence.
Example
Here is a basic task:
from cadence import Task
class Test(Task):
def run(self):
print("My first task!")
Configuration
Tasks can be configured with member variables:
Field | Type | Description |
---|---|---|
name | Optional[str] | The human-readable task name. Default is the class name. |
id | Optional[str] | A unique ID. Default is a generated UUIDv4 |
active | Optional[bool] | Whether the task is active. Default is True . |
job | Union[schedule.Job, List[schedule.Job]] | How frequently this task runs. Default is every 2 hours |
test | Optional[Callable] | The default method used to run the task. |
Take the following task as an example:
from cadence import Task
class Test(Task):
name = "Test Task"
id = "12345"
active = False
job = schedule.every(5).seconds
def test(self):
# ...
The task name is Test Task
with an ID of 12345
. This test is scheduled to run every 5 seconds, but will not run
since it is set to inactive.
You can also use lifecycle methods in place of the test
method to create a more
structured test:
from cadence import Task, before_each, step
class Test(Task):
job = schedule.every(5).seconds
drivers = None
@before_all()
def setup_drivers(self):
self.driver = configure_driver()
@step()
def get_url(self):
self.driver.get("https://cadence.io")