feat: add work-level play tracking
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-05-09 19:56:59 +08:00
parent 32a1530ab1
commit 3ad1075227
24 changed files with 1452 additions and 105 deletions

View File

@@ -339,22 +339,60 @@ impl SpacetimeClient {
&self,
user_id: String,
) -> Result<(), SpacetimeClientError> {
let procedure_input = build_runtime_profile_task_center_get_input(user_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
let normalized_user_id = user_id.trim().to_string();
let occurred_at_micros =
shared_kernel::offset_datetime_to_unix_micros(time::OffsetDateTime::now_utc());
let day_key = runtime_profile_beijing_day_key(occurred_at_micros);
self.record_tracking_event(
format!("daily-login:{}:{}", normalized_user_id, day_key),
"daily_login".to_string(),
DomainRuntimeTrackingScopeKind::User,
normalized_user_id.clone(),
Some(normalized_user_id.clone()),
Some(normalized_user_id),
None,
Some("profile".to_string()),
"{}".to_string(),
occurred_at_micros,
)
.await
}
pub async fn record_tracking_event(
&self,
event_id: String,
event_key: String,
scope_kind: DomainRuntimeTrackingScopeKind,
scope_id: String,
user_id: Option<String>,
owner_user_id: Option<String>,
profile_id: Option<String>,
module_key: Option<String>,
metadata_json: String,
occurred_at_micros: i64,
) -> Result<(), SpacetimeClientError> {
let procedure_input = crate::module_bindings::RuntimeTrackingEventInput {
event_id,
event_key,
scope_kind: map_runtime_tracking_scope_kind(scope_kind),
scope_id,
user_id,
owner_user_id,
profile_id,
module_key,
metadata_json,
occurred_at_micros,
};
self.call_after_connect(move |connection, sender| {
connection
.procedures()
.record_daily_login_tracking_event_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_tracking_event_procedure_result);
send_once(&sender, mapped);
},
);
.record_tracking_event_and_return_then(procedure_input, move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_tracking_event_procedure_result);
send_once(&sender, mapped);
});
})
.await
}
@@ -885,3 +923,9 @@ impl SpacetimeClient {
.await
}
}
fn runtime_profile_beijing_day_key(occurred_at_micros: i64) -> i64 {
const PROFILE_TASK_BEIJING_OFFSET_MICROS: i64 = 28_800_000_000;
const PROFILE_RUNTIME_DAY_MICROS: i64 = 86_400_000_000;
(occurred_at_micros + PROFILE_TASK_BEIJING_OFFSET_MICROS).div_euclid(PROFILE_RUNTIME_DAY_MICROS)
}