pub enum EventData<'a> {
    Exec {
        content: &'a str,
        args: &'a str,
        envs: &'a str,
        dir: Option<&'a Path>,
    },
    ExecDone {
        code: i32,
        main_event_id: i64,
    },
    Read,
    Write,
    Miss,
}

Variants§

§

Exec

Fields

§content: &'a str
§args: &'a str
§envs: &'a str
§dir: Option<&'a Path>
§

ExecDone

Fields

§code: i32
§main_event_id: i64
§

Read

§

Write

§

Miss

Implementations§

Examples found in repository?
src/lib.rs (line 235)
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
    pub async fn record(&self, event: &Event<'_>) -> Result<i64, DBError> {
        log::debug!("記錄事件 {:?}", event);
        let ty = event.data.get_type().get_code();
        let cmd = std::env::args().collect::<Vec<_>>().join(" ");
        let mut db_event = DBEvent::new(event.script_id, event.time, ty, &cmd, event.humble);
        let id = match &event.data {
            EventData::Write | EventData::Read | EventData::Miss => {
                self.raw_record(db_event).await?
            }
            EventData::Exec {
                content,
                args,
                envs,
                dir,
            } => {
                let mut content = Some(*content);
                let last_event = sqlx::query!(
                    "
                    SELECT content FROM events
                    WHERE type = ? AND script_id = ? AND NOT content IS NULL
                    ORDER BY time DESC LIMIT 1
                    ",
                    ty,
                    event.script_id
                )
                .fetch_optional(&*self.pool.read().unwrap())
                .await?;
                if let Some(last_event) = last_event {
                    if last_event.content.as_deref() == content {
                        log::debug!("上次執行內容相同,不重複記錄");
                        content = None;
                    }
                }
                db_event.content = content;
                let dir = dir.map(|p| p.to_string_lossy()).unwrap_or_default();
                self.raw_record(db_event.envs(envs).dir(dir.as_ref()).args(args))
                    .await?
            }
            EventData::ExecDone {
                code,
                main_event_id,
            } => {
                let main_event = sqlx::query!(
                    "SELECT ignored, humble FROM events WHERE type = ? AND id = ?",
                    EXEC_CODE,
                    main_event_id
                )
                .fetch_optional(&*self.pool.read().unwrap())
                .await?;
                let main_event = match main_event {
                    Some(e) => e,
                    None => {
                        log::warn!("找不到主要事件,可能被 tidy 掉了");
                        return Ok(ZERO);
                    }
                };
                if main_event.ignored {
                    return Ok(ZERO);
                } else if main_event.humble {
                    log::debug!("謙卑地執行完畢了");
                    db_event = db_event.humble();
                }

                let code = code.to_string();
                let id = self
                    .raw_record(db_event.content(&code).main_event_id(*main_event_id))
                    .await?;

                if db_event.humble {
                    // XXX: 用很怪異的方式告訴外面的人不要記錄最新時間,醜死
                    ZERO
                } else {
                    id
                }
            }
        };
        Ok(id)
    }

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.