createActionJob
createActionJob は、アクションをジョブとして実行する関数です。
基本的な使い方
import {
createActionJob,
showSuccessToast,
showErrorToast,
Form,
VStack,
Box,
TextInput,
Checkbox,
DateTimePicker,
Button,
} from "@basemachina/view";
const App = () => {
const initialValues = {
// アクションの引数
message: "",
// 以下、createActionJob関数のオプション
scheduledAt: null,
redirect: true,
};
const handleSubmit = async ({ values }) => {
const { message, redirect, scheduledAt } = values;
try {
const { actionJobId } = await createActionJob(
// actionId
"job-test",
// args
{ message },
// options
{ redirect, scheduledAt },
);
showSuccessToast(`ジョブ: ${actionJobId} を作成しました`);
} catch (err) {
showErrorToast(err.message);
}
};
return (
<Form initialValues={initialValues} onSubmit={handleSubmit}>
<VStack>
<Box>
<TextInput name="message" label="メッセージ" />
</Box>
<Box>
<DateTimePicker name="scheduledAt" label="予約実行日時" />
</Box>
<Checkbox name="redirect" label="自動でジョブ詳細に遷移する" />
<Button type="submit" title="ジョブを作成する" color="blue" />
</VStack>
</Form>
);
};
export default App;詳細なインターフェース
引数
| 引数名 | 型 | 必須 ・ 任意 | 説明 | 例 |
|---|---|---|---|---|
actionId | string | 必須 | 実行するアクションのID、または識別子。 | 'c3hc2ii23akg0sokf9j0', 'get-user' |
args | object | 任意 | アクションを実行するための引数で、 キーがパラメータ名、値がパラメータに渡す値のオブジェクト。 | { username: 'JohnDoe' } |
options | object | 任意 | ジョブの詳細設定。 | { scheduledAt: 1609459200 } |
options.scheduledAt | Date | string | number | 任意 | ジョブの予約実行日時。stringはDate型に変換できる値、numberはUnixTimestamp (秒)を入力してください。日時は現在から30日以内の値を指定できます。 | new Date(), '2023-01-01', 1609459200 |
options.redirect | boolean | 任意 | ジョブの作成後に、自動的にジョブ詳細画面へ移動する設定。 | true, false |
なおパラメータの入力値の種類ごとにargsへ渡せる値の型は以下です。
| 入力値の種類 | 型 | 説明 | 例 |
|---|---|---|---|
| テキスト | string | - | { company_name: '株式会社ベースマキナ' } |
| 数値 | number | null | - | { user_id: 123 } |
| 日付 | Date | string | number | null | stringはDate型に変換できる値、numberはUnixTimestamp (秒)を入力してください。 | { created: '2023-01-01', updated: new Date(), deleted: 1609459200 } |
| ファイル | File | null | - | { upload_text: new File(['test'], 'test.txt', { type: 'text/plain' }) } |
| 真偽値 | boolean | - | { checked: true } |
| JSON値 | string | number | Date | null | JSON値の種類ごとに型が異なります。 テキストなら string | null、数値ならnumber | null、日付ならstring | number | Date | nullを渡せます。日付の場合 stringはDate型に変換できる値、numberはUnixTimestamp (秒)を入力してください。 | { company_name: '株式会社ベースマキナ', user_id: 123, created: '2023-01-01', deleted: null } |
| SQL | string | - | { query: 'SELECT * FROM users;' } |
| システム値 | string | - | { offset: '20' } |
| 配列 | Array | 各要素の種類の型は、各入力値の種類の型と同じです。 | { user_ids: [10, 11, 12] } |
| タプル | Array | 各要素の種類の型は、各入力値の種類の型と同じです。 | { id_and_name: [123, 'taro'] } |
戻り値
| プロパティ名 | 型 | 説明 | 例 |
|---|---|---|---|
actionJobId | string | 作成したジョブのID。 | cpt8gkab5gv1ibk8r5h0 |