Module: Groonga::RequestTimer

Defined in:
ext/groonga/rb-grn-request-timer.c,
ext/groonga/rb-grn-request-timer.c

Overview

This module provides API for canceling requests after the specified time.

Class Method Summary collapse

Class Method Details

.default_timeoutFloat

Gets the default timeout used by request timer.

Examples:

Gets the default timeout

Groonga::RequestTimer.default_timeout

Returns The default timeout used by request timer.

Returns:

  • (Float)

    The default timeout used by request timer.

Since:

  • 6.0.2



108
109
110
111
112
113
114
115
116
# File 'ext/groonga/rb-grn-request-timer.c', line 108

static VALUE
rb_grn_request_timer_s_get_default_timeout (VALUE module)
{
    double timeout;

    timeout = grn_get_default_request_timeout();

    return rb_float_new(timeout);
}

.default_timeout=(timeout) ⇒ Float, void

Sets the default timeout used by request timer.

Examples:

Sets the default timeout

Groonga::RequestTimer.default_timeout = 2.9

Returns:

  • (Float)

    The default timeout used by request timer. If timeout is 0.0, the default timeout is disabled.

  • (void)

Since:

  • 6.0.2



131
132
133
134
135
136
137
138
139
140
# File 'ext/groonga/rb-grn-request-timer.c', line 131

static VALUE
rb_grn_request_timer_s_set_default_timeout (VALUE module, VALUE rb_timeout)
{
    double timeout;

    timeout = NUM2DBL(rb_timeout);
    grn_set_default_request_timeout(timeout);

    return Qnil;
}

.register(request_id, timeout = nil) ⇒ Groonga::RequestTimerID

Registers a request with timeout. If the request isn’t finished after the specified timeout, the request is canceled.

Examples:

Register a request that will be timed out after 2.9 seconds

request_id = "request-29"
timeout_in_second = 2.9
Groonga::RequestTimer.register(request_id, timeout_in_second)

Returns The ID of the request timer.

Parameters:

  • request_id (String)

    The ID of request to be registered.

  • timeout (nil) (defaults to: nil)

    [Float, nil] The timeout in second. If timeout is nil, default_timeout is used.

Returns:

Since:

  • 6.0.2



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'ext/groonga/rb-grn-request-timer.c', line 48

static VALUE
rb_grn_request_timer_s_register (int argc, VALUE *argv, VALUE module)
{
    VALUE rb_request_id;
    VALUE rb_timeout;
    const char *request_id;
    unsigned int request_id_size;
    double timeout;
    void *timer_id;

    rb_scan_args(argc, argv, "11", &rb_request_id, &rb_timeout);

    request_id = StringValuePtr(rb_request_id);
    request_id_size = RSTRING_LEN(rb_request_id);
    if (NIL_P(rb_timeout)) {
      timeout = grn_get_default_request_timeout();
    } else {
      timeout = NUM2DBL(rb_timeout);
    }
    timer_id = grn_request_timer_register(request_id, request_id_size, timeout);

    return GRN_REQUEST_TIMER_ID2RVAL(timer_id);
}

.unregister(timer_id) ⇒ void

Unregisters the specified request timer.

Examples:

Unregister a request timer by ID

timer_id = Groonga::RequestTimer.register("request-29", 2.9)
Groonga::RequestTimer.unregister(timer_id)

This method returns an undefined value.

Parameters:

Since:

  • 6.0.2



86
87
88
89
90
91
92
93
94
95
# File 'ext/groonga/rb-grn-request-timer.c', line 86

static VALUE
rb_grn_request_timer_s_unregister (VALUE module, VALUE rb_timer_id)
{
    void *timer_id;

    timer_id = RVAL2GRN_REQUEST_TIMER_ID(rb_timer_id);
    grn_request_timer_unregister(timer_id);

    return Qnil;
}