---
title: "Job Seeker Engagement"
description: "Keep an employer and a job seeker aligned while the job seeker decides whether to accept an opportunity."
canonical_url: "https://docs.superdurable.io/examples/job-seeker-engagement/"
source: "docs/content/use-cases/job-seeker-engagement.mdx"
locale: "en"
language: "python"
---

> Index of every page for AI agents: https://docs.superdurable.io/llms.txt

# Job Seeker Engagement

Code on this page is in Python. Other languages: [Go](https://docs.superdurable.io/examples/job-seeker-engagement.go.md) · [Java](https://docs.superdurable.io/examples/job-seeker-engagement.java.md) · [TypeScript](https://docs.superdurable.io/examples/job-seeker-engagement.typescript.md) · [Rust](https://docs.superdurable.io/examples/job-seeker-engagement.rust.md)

Keep an employer and a job seeker aligned while the job seeker decides whether to accept an opportunity.

**SDKs:** Python · Go · TypeScript · Java · Rust

**Shows:** [Static Parallel Steps](https://docs.superdurable.io/design-patterns/parallel/static-parallel-steps.md), [Reminder](https://docs.superdurable.io/design-patterns/durable-timer/reminder.md), [Decision with Deadline](https://docs.superdurable.io/design-patterns/external-interaction/decision-with-deadline.md), [Wait for Attribute Match](https://docs.superdurable.io/design-patterns/responsive-update/wait-for-attribute-match.md).

**Flow graph: EngagementFlow**

**Steps**

1. `Initialize` (start Step): Store the engagement and start the timeout, reminder, and notification paths. Next: `NotifyExternalSystem`, `ProcessTimeout`, or `Reminder`. Writes `EmployerId`, `EngagementStatus`, `JobSeekerId`, `LastUpdateTimeMillis`, `notes`.
2. `NotifyExternalSystem`: Tell the external system about the engagement status. Next: this branch ends. Reads `EmployerId`, `JobSeekerId`.
3. `ProcessTimeout`: Wait for completion or the 60-day timeout, then report the final status. Next: the Flow completes.
4. `RecordReminderOptOut`: Record the reminder opt-out in the notes under the status lock. Next: this branch ends. Reads `EngagementStatus`; locks `EngagementStatus`.
5. `Reminder`: Remind the job seeker until they respond or opt out. Next: this branch ends, `RecordReminderOptOut`, or `Reminder` again. Reads `EngagementStatus`, `JobSeekerId`, `OptOutReminder`.

**RPCs**

- `accept`: Reads `EngagementStatus`; locks `EngagementStatus`; publishes to `CompleteProcess`.
- `decline`: Reads `EngagementStatus`; locks `EngagementStatus`.
- `describe`
- `opt_out`: Publishes to `OptOutReminder`.

Example: [examples/python/dex_examples/products/engagement/engagement_flow.py](https://github.com/superdurable/dex/tree/main/examples/python/dex_examples/products/engagement/engagement_flow.py)

The graph and this description cover the Python, Go, Java, and TypeScript examples. The Rust example runs a shorter Flow; see [Rust example](https://docs.superdurable.io/examples/job-seeker-engagement.md#rust-example).

## Product requirements

The process starts with an employer ID, a job seeker ID, and notes. It must:

1. Remind the job seeker every five seconds while the status is **Initiated**. A production deployment uses a longer interval.
2. Let the job seeker opt out of reminders. The opportunity stays open.
3. Let the job seeker decline while the status is **Initiated**. A declined opportunity can still be accepted.
4. Let the job seeker accept while the status is **Initiated** or **Declined**. Acceptance completes the process with **done**.
5. Complete with **timeout** when no acceptance arrives within 60 days.
6. Tell the recruiting system when the process starts, after each decision, and when it ends.
7. Show the current status and notes, and find processes by status.

## Flow design

**Initialize** stores the participants, the status **Initiated**, and the notes. It then starts three parallel branches:

- `ProcessTimeout` waits with `AnyOf` for a 60-day Timer or a message on the `CompleteProcess` Channel. The **Accept** RPC publishes that message. `ProcessTimeout` then completes the Flow with **done** or **timeout**.
- **Reminder** waits for a five-second Timer or a message on `OptOutReminder`. It ends when the status is no longer **Initiated**. Otherwise an opt-out moves it to `RecordReminderOptOut`, and a fired Timer sends an email and moves it back to itself.
- `NotifyExternalSystem` reports the start. **Accept** and **Decline** start it again with the new status.

The two waits use separate Channels, so an opt-out cannot accept, decline, or finish the opportunity.

Status, notes, and the update time are Attributes. **Accept**, **Decline**, and `RecordReminderOptOut` share a lock on `EngagementStatus`, so each status check and note update sees the previous one's result. An opt-out keeps the status and adds a note. An RPC that finds a status it cannot change fails and starts no notification. **Reminder** sends its email without the lock.

`ProcessTimeout` completes with `GracefulComplete`, which waits for the other branches to end. After an acceptance, a running **Reminder** ends at its next Timer.

The start endpoint returns after an Attribute-match wait sees the employer ID Attribute, so a read right after the start finds the stored participants.

A real email or recruiting-system call needs an [idempotency key](https://docs.superdurable.io/concepts/step.md#idempotency-keys), because a Step that was cut off can run again. The example passes none: its sample service only logs its calls.

## Core implementation

Each tab declares the Flow and its Steps, then shows the two `AnyOf` waits. The Python tab also shows the reminder loop and the locked opt-out Step.

**Python**

```python
class EngagementFlow(Flow[EngagementInput]):
    employer_id = Attribute("EmployerId", str)
    job_seeker_id = Attribute("JobSeekerId", str)
    # dex:indexed-attribute attribute-key:EngagementStatus index-key:keyword1 index-type:keyword value-type:string description:"Current engagement status"
    engagement_status = Attribute(
        "EngagementStatus",
        Status,
        AttributeIndex(IndexType.KEYWORD, STATUS_SEARCH_KEY),
    )
    last_update_timestamp = Attribute("LastUpdateTimeMillis", int)
    notes = Attribute("notes", str)
    opt_out_reminder = Channel[None]("OptOutReminder", type(None))
    complete_process = Channel[None]("CompleteProcess", type(None))

    def __init__(self, service: MyDependencyService) -> None:
        self.service = service
        self.initialize = Initialize(self)
        self.process_timeout = ProcessTimeout(self)
        self.reminder = Reminder(self)
        self.record_reminder_opt_out = RecordReminderOptOut(self)
        self.notify_external_system = NotifyExternalSystem(self)

    def get_steps(self) -> StepList[EngagementInput]:
        return StepList.start_step(self.initialize).other_steps(
            self.process_timeout,
            self.reminder,
            self.record_reminder_opt_out,
            self.notify_external_system,
        )

    def get_persistence_schema(self) -> PersistenceSchema:
        return PersistenceSchema.of(
            self.employer_id,
            self.job_seeker_id,
            self.engagement_status,
            self.last_update_timestamp,
            self.notes,
            self.opt_out_reminder,
            self.complete_process,
        )
```

```python
class ProcessTimeout(Step[None]):
    def __init__(self, flow: "EngagementFlow") -> None:
        self.flow = flow

    def wait_for(self, context: Context, input: None) -> Wait:
        return Wait.any_of(
            Timer.by_duration(timedelta(days=60)),
            self.flow.complete_process.for_one(),
        )

    def execute(self, context: Context, input: None) -> StepDecision:
        description = self.flow.describe_engagement(context)
        result = "timeout"
        if description.current_status == Status.ACCEPTED:
            result = "done"
        self.flow.service.update_external_system(
            f"engagement from employer {description.employer_id} "
            f"to job seeker {description.job_seeker_id} "
            f"finished with status {description.current_status}"
        )
        return graceful_complete(result)
```

```python
class Reminder(Step[None]):
    def __init__(self, flow: "EngagementFlow") -> None:
        self.flow = flow

    def wait_for(self, context: Context, input: None) -> Wait:
        return Wait.any_of(
            Timer.by_duration(timedelta(seconds=5)),
            self.flow.opt_out_reminder.for_one(),
        )

    def execute(self, context: Context, input: None) -> StepDecision:
        status = self.flow.engagement_status.get(context)
        if status is not Status.INITIATED:
            return dead_end()
        if self.flow.opt_out_reminder.results(context):
            return go_to(RecordReminderOptOut, None)
        self.flow.service.send_email(
            self.flow.job_seeker_id.get(context),
            "Reminder: please respond",
            "Please respond to the engagement.",
        )
        return go_to(Reminder, None)


# dex:group group-id:reminders group-label:"Reminders"
# dex:explanation text:"Record the reminder opt-out in the notes under the status lock."
class RecordReminderOptOut(Step[None]):
    def __init__(self, flow: "EngagementFlow") -> None:
        self.flow = flow

    def get_step_options(self) -> StepOptions:
        return StepOptions(execute_lock_attributes=(self.flow.engagement_status.lock(),))

    def execute(self, context: Context, input: None) -> StepDecision:
        status = self.flow.engagement_status.get(context)
        if status is not Status.INITIATED:
            return dead_end()
        self.flow.update_status(context, status, "user opted out of reminders")
        return dead_end()
```

Example: [examples/python/dex_examples/products/engagement/engagement_flow.py](https://github.com/superdurable/dex/tree/main/examples/python/dex_examples/products/engagement/engagement_flow.py)

<a id="rust-example"></a>

## Rust example

The Rust example serves the same six playground calls but runs a shorter Flow, to keep its integration test short. One Step waits for a 24-hour Timer or one message on a decision Channel. **Accept**, **Decline**, and **Opt out of reminder** each publish one message there. The first message decides: the Step writes it as the status, `NotifyExternalSystem` records an event, and the Flow completes. A fired Timer writes the status `reminder-due` instead. Only that Step writes the status, so it needs no lock. The Rust Flow sends no reminders and has no **done** or **timeout** result.

To run it, call **Start**, then **Accept** once. **Accept** only publishes the decision, so wait for the run to close in Dex Web, or call **Describe** until it shows the status `accepted`. Make no other decision call after that, because the Flow has closed.

## Run it

<a id="demo"></a>

Start the examples of one language as in [Run an example from the playground](https://docs.superdurable.io/install.md#run-an-example-from-the-playground). In the [examples playground](https://github.com/superdurable/dex/tree/main/examples/playground), open **Job seeker engagement**. For Python, Go, Java, or TypeScript, call **Start**, then **Opt out of reminder**, **Decline**, and **Accept** with the returned Flow ID. For Rust, follow [Rust example](https://docs.superdurable.io/examples/job-seeker-engagement.md#rust-example). **Describe** shows the status and notes. **List / search** runs a search query: `keyword1 = 'Accepted'` finds accepted runs, and the default `ExecutionStatus="Running"` finds running runs.

After **Accept**, the message wakes `ProcessTimeout`. The Flow completes with **done** once **Reminder** ends at its next Timer. In Dex Web, open **Events**. **Timeline** shows the acceptance message, and **Graph** shows the Step executions. The screenshots come from the Go example.

[![Dex Web Timeline showing the engagement run from opt-out through acceptance](https://docs.superdurable.io/img/use-cases/job-seeker-engagement-timeline.png)](https://docs.superdurable.io/img/use-cases/job-seeker-engagement-timeline.png)

[![Dex Web Graph showing the engagement run from opt-out through acceptance](https://docs.superdurable.io/img/use-cases/job-seeker-engagement-graph.png)](https://docs.superdurable.io/img/use-cases/job-seeker-engagement-graph.png)

## Next

- [Deal DSL](https://docs.superdurable.io/examples/deal-dsl.md)
- [Reminder](https://docs.superdurable.io/design-patterns/durable-timer/reminder.md)
- [Decision with Deadline](https://docs.superdurable.io/design-patterns/external-interaction/decision-with-deadline.md)
- [Responsive update](https://docs.superdurable.io/design-patterns.md#responsive-update)
- [Attribute match](https://docs.superdurable.io/design-patterns/responsive-update/wait-for-attribute-match.md)
