Skip to main content

Job Seeker Engagement

View as Markdown

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, Reminder, Decision with Deadline, Wait for Attribute Match.

The graph and this description cover the Python, Go, Java, and TypeScript examples. The Rust example runs a shorter Flow; see 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, 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.

engagement_flow.pyPython
class EngagementFlow(Flow[EngagementInput]):
employer_id = Attribute("EmployerId", str)
job_seeker_id = Attribute("JobSeekerId", str)
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,
)
engagement_flow.pyPython
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)
engagement_flow.pyPython
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)


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

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

Start the examples of one language as in Run an example from the playground. In the 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. 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

Dex Web Graph showing the engagement run from opt-out through acceptance

Next